Thursday, April 28, 2005

Confirming Submission of a Form with JavaScript

If a function returns false inside the submit button the form will not submit. So you can use the onClick event handler to have a popup message appear asking if all the input is correct. Your submit button should look like this:

input class="button" value="Submit" name="Submit" onclick="return ConfirmSubmit();" type="submit"

Now write some code for the function ConfirmSubmit() inside the head section. Remember to close the code with {script language="javascript"} ... {/script} except replace the curly braces with > and <.


// function ConfirmSubmit()
// {
// var agree = confirm("Is this correct?");
// if (agree)
// return true;
// else
//
// return false;
// }


You can also, in have an onSubmit event handler.

No comments:

Labels

Blog Archive

Contributors