JavaScript form submitting when not validating -
i'm using next js validate form when submitting:-
function validate() { if( document.square.posx.value == "" ) { alert( "please pick in square think are" ); document.myform.posx.focus() ; homecoming false; } homecoming true; } <form name="square" action="save_results.php" method="post" onsubmit="return validate();"> <input type="text" id="posx" name="posx"> <input type="submit" value="submit"> </form>
when field 'posx' empty , nail submit see alert popup in browser, when click ok form still submits.
how can prevent submitting unless form fields not empty?
thanks
you have copy&paste error in script: see form name: document.square.posx.focus() ;
function validate() { if( document.square.posx.value == "" ) { alert( "please pick in square think are" ); document.square.posx.focus() ; homecoming false; } homecoming true; }
javascript
No comments:
Post a Comment