SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation -- Title is pulling through as value

    Hi

    I have been working on a project and created my forms using an infield label technique with jQuery that placed the title as the label and on focus it disappeared. That works exactly how i wanted it too however it has created a huge problem because the title must be mistaken for a value and the mandatory fields are being ignored and if a user doesn't input anything into the field the value is coming through in the enquiries as the title.

    My question is - how do I validate my form by adding a rule of if the value equals the title to send back an error and prompt the user to enter a correct value?

    Here is an example of a form on my site:
    http://www.bristolstreet.co.uk/contact-us/

    The code for the field label is:

    Code:
    	$('input[title], textarea[title]').each(function() {
    		if($(this).val() === '') {
    			$(this).val($(this).attr('title'));	
    		}
    		
    		$(this).focus(function() {
    			if($(this).val() == $(this).attr('title')) {
    				$(this).val('').addClass('focused');	
    			}
    		});
    		$(this).blur(function() {
    			if($(this).val() === '') {
    				$(this).val($(this).attr('title')).removeClass('focused');	
    			}
    		});
    	});
    Any help would be greatly appreciated
    Rachel

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function FValidateInput(control,msg)
    
    {
    
     if (control.value== "" || control.value==control.title)
    
        {
    
        control.focus()
    
        alert(msg)
    
        return false
    
        }
    
     return true
    
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •