469,632 Members | 1,767 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

capturing innerHTML content through POST

34
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
Dec 6 '07 #1
6 2154
acoder
16,027 Expert Mod 8TB
The innerHTML of what?
Dec 6 '07 #2
gsherp
34
the innerHTML of a span element with text only, no form elements.
Dec 7 '07 #3
acoder
16,027 Expert Mod 8TB
So you want to post this innerHTML content to the server without using form elements?
Dec 7 '07 #4
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]
Dec 7 '07 #5
Also if you use XMLHttpRequest you later can remove all the hidden inputs from code.

Dan
Dec 7 '07 #6
gsherp
34
thanks,
I will try this.
Dec 7 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by JimMenees | last post: by
15 posts views Thread by Tony Gahlinger | last post: by
15 posts views Thread by Larry Asher | last post: by
14 posts views Thread by Brent Burkart | last post: by
4 posts views Thread by Steve Wolfie | last post: by
16 posts views Thread by Joel Byrd | last post: by
7 posts views Thread by garthusenet | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.