Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    AJAX not updating innerHTML

    All I have the following code:
    Code:
    <form name="testimonial" id="testimonial" method="post" action="">
    <table border="0" cellspacing="3" cellpadding="3">
    <tr>
    <td valign="top">Name:</td>
    <td><input type="text" name="name" id="name" value="Enter your name" onfocus="if(this.value=='Enter your name'){this.value=''}"/></td>
    </tr>
    <tr>
    <td valign="top">Message:</td>
    <td><textarea name="message" id="message" cols="30" rows="10" onfocus="if(this.value=='Enter in a testimonial'){this.value=''}">Enter in a testimonial</textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Submit Testimonial" onclick="get(this.parentNode);"/></td>
    </tr>
    </table>
    </form>
    Then I submit it using an AJAX code. I try and reset these values using the following code:
    Code:
    http_request.onreadystatechange = function() {
    if (http_request.readyState == 4) {
    if (http_request.status == 200) {
    //alert(http_request.responseText);
    result = http_request.responseText;
    document.getElementById(SpanName).innerHTML = result;
    document.getElementById('name').innerHTML = 'Enter your name';
    document.getElementById('message').innerHTML = 'Enter your message';
    } else {
    alert('There was a problem with the request.');
    }
    }
    };
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
    }
    However, it doesn't work. Any ideas why? Thanks in advance!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This isn't a php issue. Moving from php to js/ajax forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    Where is spanName? I don't see it in your table code.
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #4
    New Coder
    Join Date
    May 2010
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    change the

    "<input type="submit" name="submit" value="Submit Testimonial" onclick="get(this.parentNode);"/>"

    to

    "<input type="button" name="submit" value="Submit Testimonial" onclick="get(this.parentNode);"/>"

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    The SpanName is an actually a div and it has some PHP in it. It has nothing to do with the table. So basically I'm trying to display a query that gets executed in the div and then actually resetting the name and message fields back to their original field values that I showed in the original post.

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    all form control (<input>, <select>, <textarea>) values (the text within) is read/set via the value property.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    So just make it:

    document.getElementById('message').innerHTML.value = 'Enter your message';

    ??

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    that should give you: "… is null or not an object"

    the value property belongs to the form element object.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #9
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    So then how can I do this? Since I don't have a <form> in my JS file.

  • #10
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    you’re thinking too complicated. you may not have a <form> tag in your script, but you certainly have a form element object.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #11
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Ahh, dumb move on my part. I fixed it by doing this:
    Code:
    document.testimonial.name.value = "Enter your name";
    document.testimonial.message.value = "Enter your message";
    Thanks for pointing it out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •