Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX validation with Jquery
    text
    copied!<p>I am setting up my error message on my form with jquery and when I go and view it it does not ask that the name field be required but just the email even though I have included it. Here is my code:</p> <pre><code>&lt;form method="post" action="" id="contactform"&gt; &lt;fieldset class="first"&gt; &lt;div id="response"&gt;&lt;/div&gt; &lt;div class="name_input"&gt; &lt;input name="name" id="name" class="required" type="text" onfocus="if(this.value == 'Name'){this.value = '';}" onblur="if(this.value == ''){this.value='Name';}" value="Name" maxlength="128" /&gt; &lt;/div&gt; &lt;div id="email_input"&gt; &lt;input id="email" name="email" onfocus="if(this.value == 'Email'){this.value = '';}" onblur="if(this.value == ''){this.value='Email';}" class="required" type="text" value="Email" maxlength="128" /&gt; &lt;/div&gt; &lt;div id="button"&gt; &lt;input type="submit" class="button" name="Submit" value="" /&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>and my JS:</p> <pre><code>$(document).ready(function() { $('form #response').hide(); $('#button').click(function(e) { e.preventDefault(); var valid = ''; var required = ' is required.'; var name = $('form #name').val(); var email = $('form #email').val(); if (name == '' || name.length &lt; 2) { valid = '&lt;p&gt;Your name' + required +'&lt;/p&gt;'; } if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) { valid += '&lt;p&gt;Your email' + required +'&lt;/p&gt;'; } if (valid != '') { $('form #response').removeClass().addClass('error') .html('&lt;strong&gt;Please correct the errors below.&lt;/strong&gt;' +valid).fadeIn('fast'); } else { $('form #response').removeClass().addClass('processing').html('Processing...').fadeIn('fast'); var formData = $('form').serialize(); submitForm(formData); } }); }); </code></pre> <p>There are not any conflicts with my name tag anywhere else so I dont know what may be happening</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