Added: 24 February, 2008
Group: JavaScript
Creating warning messages in submit forms
Author: Alex
page: 1

Creating warning messages in submit forms

While building complex forms and submit inputs for your web page it is useful to allow users to modify data they have previously entered. That will give your visitors an option to update their info or contact details for example, but that can be potential


Changing of data can be easily managed with forms but when user have option to delete some details about them it can be handy to insert special JavaScript "Are you sure?" alert that will inform user that changes he is about to make cannot be undone.

In creating this simple alert button first step is to place following code into <header>

<script LANGUAGE="JavaScript">
<!--
function confirmPost()
{
var agree=confirm("ARE YOU SURE ?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>


This JavaScript function confirmPost() handle the situation when user is prompted to answer "Yes" or "Cancel".
If "Yes" is clicked script continues and if user choose "Cancel" form processing is stopped.

Of course you can change the "ARE YOU SURE ?" and write any other warning message.

Next step is placing this JavaScript function into work. In your form you have to create special input tag with onClick event:

<form action="action.php" method="post">
<input type="submit" name="Submit" value="delete" onClick="return confirmSubmit()">
</form>


Calling this Javascript with onClick event will be executed if user choose "Yes" and stopped if user choose "Cancel".

As you can see this simple and easy JavaScript can give you way to place extra protection and warning messages while allowing user option to manipulate with submitted data.

GO to: Page 1 : Creating warning messages in submit forms


TechTut.com This tutorial is copyrighted. Partial duplication or full duplication is prohibited and illegal. Translation or usage of any kind without author�s permission is illegal.