Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-19-2010, 03:03 AM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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!
treeleaf20 is offline   Reply With Quote
Old 05-19-2010, 05:24 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This isn't a php issue. Moving from php to js/ajax forum.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 05-19-2010, 07:42 AM   PM User | #3
rfresh
Regular Coder

 
Join Date: Jun 2007
Location: Los Angeles
Posts: 545
Thanks: 81
Thanked 5 Times in 5 Posts
rfresh is an unknown quantity at this point
Where is spanName? I don't see it in your table code.
__________________
RalphF
Business Text Messaging Services
https://www.MobileTextingService.com
rfresh is offline   Reply With Quote
Old 05-19-2010, 01:09 PM   PM User | #4
basilas
New Coder

 
Join Date: May 2010
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
basilas is an unknown quantity at this point
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);"/>"
basilas is offline   Reply With Quote
Old 05-19-2010, 02:06 PM   PM User | #5
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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.
treeleaf20 is offline   Reply With Quote
Old 05-19-2010, 02:43 PM   PM User | #6
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,860
Thanks: 9
Thanked 290 Times in 286 Posts
Dormilich is on a distinguished road
all form control (<input>, <select>, <textarea>) values (the text within) is read/set via the value property.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 05-19-2010, 02:50 PM   PM User | #7
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
So just make it:

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

??
treeleaf20 is offline   Reply With Quote
Old 05-19-2010, 02:53 PM   PM User | #8
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,860
Thanks: 9
Thanked 290 Times in 286 Posts
Dormilich is on a distinguished road
that should give you: "… is null or not an object"

the value property belongs to the form element object.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 05-19-2010, 02:54 PM   PM User | #9
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
So then how can I do this? Since I don't have a <form> in my JS file.
treeleaf20 is offline   Reply With Quote
Old 05-19-2010, 02:56 PM   PM User | #10
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,860
Thanks: 9
Thanked 290 Times in 286 Posts
Dormilich is on a distinguished road
you’re thinking too complicated. you may not have a <form> tag in your script, but you certainly have a form element object.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 05-19-2010, 03:30 PM   PM User | #11
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
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.
treeleaf20 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:22 PM.


Advertisement
Log in to turn off these ads.