Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating a form in Javascript not working
    primarykey
    data
    text
    <p>I'm trying to validate a form using JavaScript, but the code doesn't seem to execute. The Form is being processed using php which is working just fine. But, the validation is not working. Can someone please help me with this.</p> <pre><code>&lt;script&gt; function validateForm(){ var x = document.getElementById('name'); var email = document.getElementById('email'); var num = document.getElementById('number'); var size = document.getElementById('size'); var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; var atpos=email.value.indexOf("@"); var dotpos=email.value.lastIndexOf("."); if (x.value == null || x.value == "") { alert("Please Enter your name"); x.foucs; x.style.background = 'Yellow'; return false; } if(!filter.test(email.value){ alert('Please provide a valid email address'); email.focus; email.value=""; return false; } if(num.value == null &amp;&amp; num.value == ""){ alert('Please enter your mobile number'); num.focus(); } if(!isNan(num.value){ alert('Please enter a valid number'); num.focus(); num.style.background(); return false; } return false; } &lt;/script&gt; </code></pre> <p>And here is my html code.</p> <pre><code> &lt;form method="post" name="myForm " onsubmit="return validateForm()" action="myprocessingscript.php" &gt; &lt;input type="text" name="name" placeholder="Name" class="text" id="name" /&gt; &lt;input name="email" placeholder="Email" type="text" class="text" id="email"/&gt; &lt;input name="number" placeholder="Mobile Number" type="text" class="text" id="number"/&gt; &lt;input name="size" placeholder="Size" type="text" class="text" id="size" /&gt; &lt;input type="Submit" value="Submit" class="button"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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