Hi Guys,
I am new to jQuery and I am utilising it to try and improve a small business website I am making.
I am currently validating a webform which is going great. I have surprised myself how quick it was. I am writing the code in a ('body').append function. Which is working in general however when the users leaves a field using the mouse pointer or tabs (to a checkbox) it does not validate. Tabbing from a text box to a text box does validate :P This has completely confused me haha
Summarise Question 1:
How do I validate the field after every key press?
The second problem I am having is emailing the form to myself. I have written a php file which validates the fields server-side and emails them to myself but I am struggling to work out how I call the php script from jQuery so it uses the same submit form.
Summarise Question 2:
How do I call emailForm.php at the end of my .js file?
Here is a snippet of the first validation to give you a picture of my code :)
- $(document).ready(function(){
- var jVal = {
- 'fullName' : function() {
-
- $('body').append('<div id="nameInfo" class="info"></div>');
- var nameInfo = $('#nameInfo');
- var ele = $('#fullname');
- var pos = ele.offset();
-
- nameInfo.css({
- top: pos.top-3,
- left: pos.left+ele.width()+15
- });
- if(ele.val().length < 6) {
- jVal.errors = true;
- nameInfo.removeClass('correct').addClass('error').html('← at least 6 characters').show();
- ele.removeClass('normal').addClass('wrong');
- } else {
- nameInfo.removeClass('error').addClass('correct').html('√').show();
- ele.removeClass('wrong').addClass('normal');
- }
- }