开发者

Get HTML Content Upon Submit

In Jsp while i press submit button instead of passing values to action开发者_如何学编程. I want the HTML content of that form with all values it is possible??

If possible give an example. Let me know if any clarification is needed.


It isnt clear where do you need this html content?

If on browser, use an alert in an onSubmit event -

alert(document.myForm.innerHTML);

To get this on to server side, you will need to pass this content as part of form submission, maybe in a hidden field.

in onSubmit() event:
myForm.myHiddenHtmlContent = myForm.innerHTML;

For InnerHTML with current form values: Its not plain easy, check out the following link - innerHTML with current form values This uses jquery, but you can also write your own without it as well.

Including an example - Ok, it looks like it works in IE but not in FireFox. Basically you need to setAttribute('value') for each form element to make it work.

Use following -

var formElements = document.getElementById("myFormId").elements;
for (var x = 0; x <= formElements.length - 1; x++)
{
    if (formElements[x].value) {
        formElements[x].setAttribute("value", formElements[x].value);
    }
}

//Now you are ready to call innerHTML
myForm.myHiddenHtmlContent = myForm.innerHTML;

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜