Pages

Wednesday, May 25, 2011

Java Script: Display Confirmation Dialog prior to Form submit.

How to display a confirmation dialog, prior to form submit ?
We achieve this  using Java Script.


The following java script code will do this.

<script type="text/javascript">
 
function confirmSubmit(){
var agree=confirm("Do you wish to continue?.This action cannot be undone.");
if (agree)
return true ;
else
return false ;
}
</script>
 
 In the Form element, we will have a submit button.
In that just call the java script code on onClick event of the button, as follows.
 
<input type="submit"  value='Submit' onClick="return confirmSubmit()"/>  
 
Just include the java script code at the end of title tag. 
(i.e)In between title tag and head tag. 

No comments:

Post a Comment