Note that there are some explanatory texts on larger screens.

plurals
  1. POForm validation: multiple check made on the same script gives an error
    text
    copied!<p>I have created a script which checks if an email is valid. I have another function which checks if a username is taken. When checking both textboxes I get 'error on page' if these are checked on there own it works fine.</p> <p>Below is my code</p> <pre><code>&lt;script type="text/javascript"&gt; function AjaxFunction() { var httpxml; try { // Firefox, Opera 8.0+, Safari httpxml=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { httpxml=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpxml=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } function stateck() { if(httpxml.readyState==4) { document.getElementById("msg").innerHTML=httpxml.responseText; } } httpxml.open("GET",ajax.php,true); httpxml.send(null); } &lt;/script&gt; &lt;form name=form action=''&gt; Username &lt;input type=text name=username onBlur="AjaxFunction();"&gt;&lt;br&gt;&lt;div id="msg"&gt;&lt;/br&gt;&lt;/div&gt;&lt;br&gt; Email Address&lt;input type=text name=email onBlur="AjaxFunction();"&gt;&lt;div id="msg"&gt;&lt;/div&gt; &lt;br&gt; &lt;input type=submit value=Submit &gt; &lt;/form&gt; </code></pre> <p>This is my ajax.php file....note the function for checking is not on this page, I have simply used echo $username as an example of this not working.</p> <pre><code>&lt;? $username=$_GET['username']; echo $username; $email = $_GET['email']; if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)){ echo "&lt;font color=red&gt; Invalid email&lt;/font&gt;"; }else{ echo "&lt;font color=green&gt; Valid Email&lt;/font&gt;";} ?&gt; </code></pre> <p>Thanks =)</p>
 

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