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 6692021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:49:10+00:00 2026-05-26T05:49:10+00:00

Having a few issues with jquery .html() . Below is a code which changes

  • 0

Having a few issues with jquery .html(). Below is a code which changes a text box input value from “Enter email address” to “” when they focus, and if they haven’t entered anything, puts “Enter email address” back on blur.

I’m using jquery .html() with .post() to phpmailer to update the containing div with “Sending…” “Successfully sent” “Failed”, etc.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
     $("#emailaddressinput").focus(function(){
          if ($(this).val() == 'Enter email address') {
               $(this).val('');
          }
     });
     $("#emailaddressinput").blur(function(){
          if (!$.trim($(this).val())) {
               $(this).val('Enter email address');
          }
     });
});
</script>

Here’s the code that POSTS to phpmailer. On success the response is 'true'. However, when it fails, it uses dotimeout.js to delay 3 seconds and then uses jquery .html to put the original form back in place. When it does this, the above code doesn’t work anymore. At the bottom is my original html.

<script src="lib/dotimeout.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
     $('#emailbutton').click(function(e) {
          e.preventDefault();
          var email = $('#emailaddressinput').val();
          //write 'sending...' or something
          $('#emailinputcontainer').html('Sending, please wait.');
          var generated_coupon_id = '2';
          var dataString = 'email=' + email + '&generated_coupon_id=' + generated_coupon_id;
          $.post('send.php', dataString, function(data){
               //do stuff
               if(data=='true'){
                    //say "message sent!"
                    $('#emailinputcontainer').html('Your coupon has been emailed!');
               } else {
                    //say error
                    $('#emailinputcontainer').html('There was an error. Please try again.');
                    $.doTimeout(3000,function() {
                         $('#emailinputcontainer').html('<input id="emailaddressinput" type="text" value="Enter email address" /><a id="emailbutton" href="#" style="margin: 0 !important;"><span class="buttontext" >Email coupon</span></a>');
                    });
               }
          });
     });
});
</script>

Here is the original html of the form:

<div id="emailinputcontainer">
    <input id="emailaddressinput" type="text" value="Enter email address" /><a id="emailbutton" href="#" style="margin: 0 !important;"><span class="buttontext" >Email coupon</span></a>
</div>

How do I get my original script at the top of this page to work again when the email fails and I use .html() to reload the original contents.

EDIT: Actually, I tinkered further and now the .post() won’t work which is much more important!

  • 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-05-26T05:49:10+00:00Added an answer on May 26, 2026 at 5:49 am

    What you are looking for is .live(). When you call $(“#emailaddressinput”).focus() jQuery finds the element #emailaddressinput in the DOM and binds the function to that element. When you replace the html in your javascript it is no longer the same element, but rather a new one that looks the same. .live() continues to watch the DOM for changes and binds to new elements as they are created.

    for information on using .live see http://api.jquery.com/live/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a few issues with JQuery traversal and looking for some asssistance.. If i
Am having a few issues with the Jquery Validation plug in, and wondering if
I'm having issues with some jQuery code I have. Using $.each I am looping
I am using jquery.alerts on my website and I am having a few issues
I am having a few issues when people are trying to access a MySQL
Over the past few years I've changed from having a long flowing page of
Having a problem getting a TreeView control to display node images. The code below
I'm a rookie designer having a few troubles with this page: http://www.resolvegroup.co.nz/javasurvey.php There are
Having read up on quite a few articles on Artificial Life (A subject I
Having worked with Classic ASP for about 2 years now by creating a few

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.