Skip to content Skip to sidebar Skip to footer

Working On A Onsubmit

I am working on a form. I need to have a onsubmit form handler. And to create a validation script to make sure the fields are not empty. When I go to this when I click the submit

Solution 1:

Make note that:

if (themessage == "You are required to complete the following fields: ") {

will return false if themessage equals anything more than just that; which means it will always fail. I recommend, instead, you do something else to determine if there are unfilled fields, like a boolean value (a var holding true or false.) It will cause duplicate code, but I'm sure it can be re-factored in a way where it won't, like using if/else chains.

Solution 2:

JavaScript is case sensitive.

Change this:

FunctionconfirmSubmit(){

To this instead:

function confirmSubmit(){

With your current code you simply get syntax error so there's nothing running upon sumission.

Solution 3:

You should set the attribute action to action="javascript:" to avoid the default form submit.

Then set your button as type="submit" instead of button

And finally set the action as an onclick on the submit button. When the user hit enter or click the submit button, the event will fire.

Post a Comment for "Working On A Onsubmit"