admin管理员组

文章数量:1289857

I want to have a form and need to submit it to a url in a new pop up window on button onclick action. I want something like this.

<form id = "test" name = "test" action = "preview.jsp">
    Email : <input type = "text" name = "email"/>
    <button id = "submitButton" onclick = "submitFormInPopUp()"/>
</form> 

So how to write this function submitFormInPopUp() which posts to action url in a new pop up page.

Thanks

Jitendra

I want to have a form and need to submit it to a url in a new pop up window on button onclick action. I want something like this.

<form id = "test" name = "test" action = "preview.jsp">
    Email : <input type = "text" name = "email"/>
    <button id = "submitButton" onclick = "submitFormInPopUp()"/>
</form> 

So how to write this function submitFormInPopUp() which posts to action url in a new pop up page.

Thanks

Jitendra

Share Improve this question asked Apr 18, 2011 at 8:21 RandomQuestionRandomQuestion 6,99818 gold badges66 silver badges100 bronze badges 3
  • 1 how do you want to create a popup? on different window or same window?? – S L Commented Apr 18, 2011 at 8:24
  • check the answer provided it'll help you – Harish Commented Apr 18, 2011 at 8:51
  • Thanks all for quick responses. Answers by wong2 and Anand works. – RandomQuestion Commented Apr 18, 2011 at 9:22
Add a ment  | 

3 Answers 3

Reset to default 6

Use this:

function submitFormInPopUp() 
{
 window.open('','Prvwindow','location=no,status=no,toolbar=no,scrollbars=yes,width=730,height=500');

 document.test.action = "preview.jsp"
 document.test.target = "Prvwindow"
 document.test.submit(); 
}

i hope its help to u

function submitFormInPopUp(){
    var url = "preview.jsp?email=" + document.getElementsByTagName('input')[0].value;
    window.open(url);
}

Maybe you could use the target attribute?

http://www.w3schools./TAGS/att_form_target.asp

Change the button type to submit and specify target, you don't need any javascript.

<form id="test" name="test" action="preview.jsp" target="_blank">
    Email : <input type = "text" name = "email"/>
    <input type="submit" value="Submit" id="submitButton" />
</form> 

Be aware though it's deprecated and not allowed in Strict.

本文标签: javascriptHow to submit form in new pop up on button onclick actionStack Overflow