Connecting Tech Pros Worldwide Forums | Help | Site Map

capturing innerHTML content through POST

Member
 
Join Date: May 2007
Posts: 34
#1: Dec 6 '07
Hi,
Is there easy way of capturing innerHTML content when the user submits the form? I tried using a hidden input field which works, however...is there any other way of doing this without using hidden input field?

Thanks,
Dave

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Dec 6 '07

re: capturing innerHTML content through POST


The innerHTML of what?
Member
 
Join Date: May 2007
Posts: 34
#3: Dec 7 '07

re: capturing innerHTML content through POST


the innerHTML of a span element with text only, no form elements.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Dec 7 '07

re: capturing innerHTML content through POST


So you want to post this innerHTML content to the server without using form elements?
Newbie
 
Join Date: Dec 2007
Posts: 13
#5: Dec 7 '07

re: capturing innerHTML content through POST


I hope this helps:

[HTML]function sendData() {
var form = document.getElementById('myForm');
inputNode = document.createElement("input");
inputNode.type = "hidden";
inputNode.name = "hiddenKey";
inputNode.value = document.getElementById('key').innerHTML;
form.appendChild(inputNode);
document.myForm.submit();
}[/HTML]

and the HTML code:
[HTML]<form action="mypage" name="myForm" id="myForm" method="get">
<span id="key">some data</span>
<input type="button" onclick="sendData();return false;" value="submit" />
</form>[/HTML]
Newbie
 
Join Date: Dec 2007
Posts: 13
#6: Dec 7 '07

re: capturing innerHTML content through POST


Also if you use XMLHttpRequest you later can remove all the hidden inputs from code.

Dan
Member
 
Join Date: May 2007
Posts: 34
#7: Dec 7 '07

re: capturing innerHTML content through POST


thanks,
I will try this.
Reply