# Javascript Yes No popup windows



## peterjcs

I have a form and when user click on the submit button, a javascript windows will pop up. User can choose yes or no. When click yes, the pop up will close and submit the form and if click no, just close the pop up window.

I know some basic how to create a pop up windows, but just does not know how to make it when click yes, will submit form! I think need to return value true to the form, so the form action will start!

Could someone help me? Thank in advance.



HTML:


<form name="form1" method="post" action="process.php" onSubmit="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>


----------



## jamiemac2005

Hey, you can take a look here for the type of box you are looking for and how to use it:

http://www.tizag.com/javascriptT/javascriptconfirm.php

I think what you want to do is something along the lines of this:



Code:


<form ... onSubmit="return confirm('do you want to submit the data?');" ...>

Try it out and if it doesn't work then take a look at that tutorial and i'm sure you'll work it out.

Hope it helps,
Jamey


----------



## peterjcs

Thank for your reply. But i want to pop up a window. When user click the yes button on pop up windows, then the pop up windows will return true and submit the form.

How to return true to the main form? Is it possible using the javascript opener?


----------



## jamiemac2005

oh, so you're going to open a pop-up with yes/no button elements inside, and then act upon that? To be honest i don't know, you may get better help on the javascript part of this forum: www.webdeveloper.com


----------



## peterjcs

Hai, I finally found the way to do it. But any comment or improvement to the code is appreciated.

Below is the sample:


HTML:


<html>
<head>
<title>Untitled Document</title>
<script>
function confirm(url) {

window.open(url, "test", "width=200,height=20");

} 

</script>
</head>

<body>
<form name="form1" method="post" action="submit.html">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="button" name="Button" value="Button" onClick="confirm('test.html')"></td>
    </tr>
  </table>
</form>
</body>
</html>




HTML:


<html>
<head>
<title>Untitled Document</title>
<script>
function submitform(){

window.close();
opener.document.forms['form1'].submit();

}

</script>
</head>

<body>
<p> </p>
<div align="center">
  <input type="button" name="Button" value="Yes" onClick="submitform();">
    
  <input type="button" name="Submit2" value="No" onClick="window.close()">
</div>
</body>
</html>




HTML:


<html>
<head>
<title>Untitled Document</title>
</head>

<body>
submit successfully.
</body>
</html>


----------

