Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript validation doesn't work in my PHP
    text
    copied!<p>I have a simple Javascript validation code that works fine if I send it to a certain PHP address, while it doesn't work if I send it to a PHP page I have created.</p> <p>The code is quite basic at the moment and validates some fields with regexes.</p> <p>Basically, if I try it with a given ready-made PHP file (I can't access) it works fine presenting me the error dialog box until all the fields are correct.</p> <p>Meanwhile, in the PHP page I made, it catches the error, display the dialog box but on the OK alert box click, it submits the fields to my PHP file.</p> <p>Can someone give me a clue of what's going on?</p> <p>Thank you.</p> <p><strong>This is the Javascript:</strong></p> <pre><code>&lt;script type="text/javascript"&gt; /* &lt;![CDATA[ */ // this function calls all the other functions that validate each field of the submitting form function validate() { var validated = false; validated = validateRId() &amp;&amp; validateEId(); return validated; } // this validates the RID: checking that the field is filled with a 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 your RID (a number range 1 to 99999))"); RIdElement.focus(); return false } } // this validates the EventID: checking that the field is filled with a number between 1 and 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 the EID (a number range 1 to 99999))"); EIdElement.focus(); return false } } /* ]]&gt; */ &lt;/script&gt; &lt;p/&gt; &lt;form action="http://adress.php" method="post" name="submitrunnertime" onsubmit = "return validate()"&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;Runner ID*&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="RID" id="RID" size="5" maxlength="5"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Event ID*&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="EID" id="EID" size="5" maxlength="5"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" name="submit" value="submit"/&gt; &lt;hr/&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>This is the PHP:</strong></p> <pre><code>&lt;body&gt; &lt;?php // access details as variables $username = "xxxx"; $password = "tttt"; $hostname = "rrrrr"; //connection $connection = mysql_connect($hostname, $username, $password) or die ('connection problem:' . mysql_error()); echo $connection . "CONNECTION SUCCEDED&lt;br&gt;&lt;br&gt;&lt;br&gt;"; //select a database $mydb = mysql_select_db("xxxx", $connection)or die ('db problem:' . mysql_error()); echo $mydb . " DB SELECTED &lt;br&gt;&lt;br&gt;&lt;br&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload