simpli Posted March 14, 2009 Share Posted March 14, 2009 Hi all, this validation script isnt working and I can't troubleshoot. Someone corrected it and posted a working version but I havent been able to figure out what was the problem and what was changed so that sort of leave me nowhere further than before. Can anyone look with a new pair of eyes and tell me what I am missing? Thank you in advance, J-R <script type='text/javascript'> function formValidator(){ // Make quick references to our fields document.write("Hello"); var p1 = document.getElementById('player_1'); document.write(p1.value); // Check each input in the order that it appears in the form! if(notEmpty(p1, "Please enter something, anything please!")){ return true; } return false; } function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } </script> <?php /*Form header information */ print <<<htmldebut <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <b>type something</b> htmldebut; echo '<html><head><title>Page des poolers</title></head> <body>'; //If we get here as a result of the submit button having been pushed: We are going to validate the data if(isset($_POST['submit'])){ $nbjoueurs = 1; $error=''; //initialize $error to blank for ($i=1; $i <= $nbjoueurs; $i++) { if(trim($_POST['player_' . $i])=='') { $error .="Votre joueur #" . $i . " n'a pas ete choisi!<br />"; } } //There are no errors we can write to database if($error == ''){ echo 'no errors'; }else{ echo '<fieldset style="width:450px">'; echo '<legend>Erreurs</legend>'; echo $error; echo '</fieldset>'; } } ?> <?php echo '<br/>'; echo '<fieldset>'; echo '<b><label for="player_1" style="width:2em"> 1. </label></b><input name="player_1" id="player_1" type="text" size="30"><br/>'; echo '</fieldset>'; echo '<input type="submit" name="submit" value="Soumettre vos choix">'; //End of the form ?> </form> <br/> </body></html> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 14, 2009 Share Posted March 14, 2009 Fixed: function notEmpty(elem, helperMsg){ if(elem.value.length === 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } function formValidator(){ // Make quick references to our fields document.createTextNode("Hello"); var p1 = document.getElementById('player_1'); document.createTextNode(p1.value); // Check each input in the order that it appears in the form! if(notEmpty(p1, "Please enter something, anything please!")){ return true; } return false; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.