Moon Moon - 4 months ago 8
Javascript Question

HTML - Form Submit Button Confirmation Dialog

this is a general form code

<form name="search_form" action="" method="POST">
<input type="text" name="search_text">
<input type="submit" name="search_bt" value="Go">
</form>


is there a way could have a confirmation dialog saying 'Yes'\'No' or 'Confirm'\'Cancel' etc...

One way i figured of dong is is with CSS Layer and JavaScript and Php... that have a php
isset(){}
chechk on the button and when set display a Div displayed with two buttons and
onclick=func()
JS function of those buttons have a php variable(flag) set and then i can
if(flag){}
to continue or skip some code...

well that is going to work and plus point is that i can have a well themed dialog box but i just wanna make my life easier...

Answer

You can also do it with one line in the form tag itself

<form action="exampleHandlerPage.php" method="post" onsubmit="return confirm('Are you sure you want to submit?');">
Comments