RandomQuestion
RandomQuestion

Reputation: 6998

How to submit form in new pop up on button onclick action

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

Upvotes: 2

Views: 17303

Answers (3)

Anand Thangappan
Anand Thangappan

Reputation: 3106

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

Upvotes: 6

František Žiačik
František Žiačik

Reputation: 7614

Maybe you could use the target attribute?

http://www.w3schools.com/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.

Upvotes: 0

wong2
wong2

Reputation: 35760

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

Upvotes: 0

Related Questions