Skip to content Skip to sidebar Skip to footer

Prevent Form From Posting Until Javascript Code Is Satisfied

whenever i click on submit button it fires alert('empty username') but goes a head and directs me to checklogin.php...how can i avoid that and let it remain on the page unless the

Solution 1:

in the submit input you can add the event handler of onsubmit like this:

<inputtype="submit" value="submit form" onsubmit="return RequiredFields();"/>

the RequiredFields will return false if not all the required fields are full and the submit process will stop.

Solution 2:

When you change your submit to this it won't submit if RequiredFields returns false.

<inputtype="submit" value="Login" onsubmit="return RequiredFields();"/>

Solution 3:

Use this code

<inputtype="submit" value="Login" onclick="return RequiredFields()" />

Solution 4:

I think this might work.

function xyz(event)
    {
      event.preventDefault(); // while the function returns false
    }

also you may use HTML5 attribute required to avoid javascript overburden. <*input type="" required>*

Post a Comment for "Prevent Form From Posting Until Javascript Code Is Satisfied"