Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:13:55+00:00 2026-06-01T00:13:55+00:00

I have tried to replace the submit button of a form with an ajax

  • 0

I have tried to replace the submit button of a form with an ajax loader as part of my ajax request.

Here is the code i used:

beforeSend: function() {
  $("#submit").replaceWith("<img id='loader' width ='14px' src='../img/loader.gif'>");
},
success: function(data){
  $("#loader").replaceWith("<input id='submit' type='submit' class='button blue' value='Get History'  />");

This works for the first submit, the loader shows then i get the button back on ajax complete but the button no longer submits the form?

EDIT:
Here is the form

    <form id="history" action="temp_history.php" method="post" onsubmit="getHistory();return false;" >
<?php
foreach($_SESSION['contacts'] as $user => $id) {?>
<li class="contactList"><span><input type="checkbox" name="contact[]" id="contact" value="<?php echo $id; ?>" /></span><?php echo $user; ?></li>
<?php } ?>
</div>
</ul>
  <div style="bottom: 0; position: absolute; text-align: left; margin-bottom:10px; margin-left:10px; width: 210px;">
  <input type="text" name="days" id="days" style="border:0; color:#8a8a8a; font-weight:bold; background: url(../img/nav_secondary_bg.png);" readonly="readonly" />
  <div id="slider"></div>
  <input id="submit" type="submit" class="button blue" value="Get History"  />
  <input type="button" class="button grey" value="Clear"  />
  </div>
</form>

Entire Function:

function getHistory() {
    //var contact = $("#contact").val()
    var contact = new Array();
      $("input[@name='contact[]']:checked").each(function() {
        contact.push($(this).val());
      });
    var days = $("#days").val()
    $.ajax({
        type: 'post',
        url: 'temp_history.php',
        data: {contact: contact, days: days},
        context: document.body,
        beforeSend: function() {
            $("#submit").replaceWith("<img id='loader' width ='14px' src='../img/loader.gif'>");
        },
        success: function(data){
            $("#loader").replaceWith("<input id='submit' type='submit' class='button blue' value='Get History'  />");
            var json = jQuery.parseJSON(data);
            var divs = "", tabs = "", counts = 0;

            jQuery("#gMap").gmap3({ action: 'clear' });
            jQuery(".marker").remove();

            jQuery.each(json, function(i, item) {
                var name = item.name;
                var userId = item.data.user;
                jQuery.each(item.data.data, function(i, nav) {
                    var ts = nav.timestamp;
                    var lat = nav.latitude;
                    var long = nav.longitude;

                    if (lat != null && long != null) {
                        addMarker(name, counts = counts + 1, ts, lat, long, userId);
                    }
                });
            })  
        }
  });

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:13:56+00:00Added an answer on June 1, 2026 at 12:13 am

    You will need to re-bind your events after .replaceWith(), as the DOM will class this as a new element with no events attached to it.

    Add after:

    $("input[type='submit'].button.blue").click(function(){
       getHistory();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page like this: <form class=ajax method=post action=add_item.php> [text input] [submit button]
I am currently trying to replace the input.submit button with an image. I have
How can I replace all line-endings in big file (>100MB)? I have tried to
I have a view with a submit button. I also have a few ActionLinks
I am working on a drupal site that has a form submit ajax call
I have webpage A. The user clicks on a form to submit data, and
I have an email form on an HTML page and once you click submit
Inside of an asp.net mvc partial view, I have an Ajax form that posts
I have a form in a jQuery tab div that is loaded with AJAX:
I am trying to 'replace' the button on select inputs. I have looked at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.