Javascript validation doesn't work in my PHP -


i have simple javascript validation code works fine if send php address, while doesn't work if send php page have created.

the code quite basic @ moment , validates fields regexes.

basically, if try given ready-made php file (i can't access) works fine presenting me error dialog box until fields correct.

meanwhile, in php page made, catches error, display dialog box on ok alert box click, submits fields php file.

can give me clue of what's going on?

thank you.

this javascript:

<script type="text/javascript">   /* <![cdata[ */   // function calls other functions validate each field of submitting form   function validate() {     var validated = false;     validated = validaterid() && validateeid();     return validated;   }   // validates rid: checking field filled number between 1    //and 99999   function validaterid() {     var ridelement =  document.getelementbyid("rid");     patternrid = /^([1-9][0-9]{0,4})$/;     if (patternrid.test(ridelement.value)) {       return true;     } else {       alert ("please enter rid (a number range 1 99999))");       ridelement.focus();       return false     }   }   // validates eventid: checking field filled number between 1 , 99999   function validateeid() {     var eidelement =  document.getelementbyid("eid");     patterneid = /^([1-9][0-9]{0,4})$/;     if (patterneid.test(eidelement.value)) {       return true;     } else {       alert ("please enter eid (a number range 1 99999))");       eidelement.focus();       return false     }   }   /* ]]> */ </script> <p/>   <form action="http://adress.php" method="post" name="submitrunnertime"  onsubmit = "return validate()">     <table>       <tr><td>runner id*</td>         <td><input type="text" name="rid" id="rid" size="5" maxlength="5"/></td>       </tr>       <tr><td>event id*</td>         <td><input type="text" name="eid" id="eid" size="5" maxlength="5"/></td>       </tr>     </table>     <input type="submit" name="submit" value="submit"/>     <hr/>   </form> </body> </html> 

this php:

<body> <?php   // access details variables   $username = "xxxx";   $password = "tttt";   $hostname = "rrrrr";   //connection   $connection = mysql_connect($hostname, $username, $password) or die ('connection problem:' . mysql_error());   echo $connection . "connection succeded<br><br><br>";   //select database   $mydb = mysql_select_db("xxxx", $connection)or die ('db problem:' . mysql_error());   echo $mydb . " db selected <br><br><br>"; ?> </body> </html> 

you have error in javascript function

try this

function validate()  {     var validated = false;     validated = validaterid() && validateeid() ;         return validated; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -