Rocket
Rocket

Reputation: 1093

Form continue confirmation?

I have a simple html form which is submitting to it's self. If any of the checkboxes on the form are ticketed I want to ask the user if they want to continue.

I only want to ask them once, NOT once for each checkbox.

This is what I currently have :

<table style="text-align: left; width: 100px;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<form id="form1" method="post" action="test.php">
<tr>
<td><input name="u_a" type="checkbox"></td>
<td><input name="a"></td>
</tr>
<tr>
<td><input name="u_b" type="checkbox"></td> <td><input name="b"></td>
</tr>
<tr>
<td><input name="u_c" type="checkbox"></td> <td><input name="c"></td>
</tr>
<tr>
<td style="text-align: center;" colspan="2" rowspan="1"><input type="hidden" name="update" value="update"><input type="submit" value="Submit" name="Submit"></td>
</tr>
</form>
</tbody>
</table>

<?php
if (isset($_REQUEST['update'])) {
    if (isset($_REQUEST['u_a']) || isset($_REQUEST['u_b']) || isset($_REQUEST['u_c'])) {
// CONFIRM CONTINUE OK=CONTINUE CANCEL=EXIT
    }
}
?>

How do I do the confirmation alert, and make the processing stop if they click cancel. If they click cancel I'd like there form values to remain so they can adjust them.

Thanks

Upvotes: 0

Views: 79

Answers (1)

John Conde
John Conde

Reputation: 219834

Use window.confirm. It allows you to base your logic on the response from the user.

if (window.confirm("Are you sure you wish to update?")) { 
  // yes, do something
}

Upvotes: 1

Related Questions