Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Posts
    512

    [JavaScript] Form validation using hidden images

    Hi everyone,

    I'd like a very simple visual form validation. The only thing i need is that i'd like an image (checkmark) to appear next to a form field (textfield, textarea, dropdown, radio, checkbox) whenever a field is filled in correctly. In general this means:

    - A radiogroup should be selected
    - A textarea and textfield should have two or more characters in it.
    - A dropdown should have a selected value (not empty).

    The real validation happens in PHP, but i just want to show the visitor little checkmarks when a field is filled in. The checkmark should be removed whenever a field is cleared again or something like that.

    I wrote a little script in Javascript but iam not good in JS. What happens now is that whenever someone clicks in any field a checkmark appears. When nothing is entered the checkmark won't dissapear.

    Code:
    function notEmpty(id)
    {
    	var myTextField = document.getElementById(id);
    	if(myTextField.value != "") myTextField.style.display = ""; 
    	else myTextField.style.display = "none"; 	
    }
    And in HTML
    Code:
    <img src="fieldempty.gif" alt="" style="display:none;" id="script" />
    
    <input name="test" type="text" id="test" onclick="notEmpty('script'); return(false);" />
    Could anyone help me out a little?

  2. #2
    Join Date
    Feb 2006
    Location
    top: 50px; left: 200px;
    Posts
    213
    Hey ic3d

    This should help you out

    http://www.livevalidation.com/

    Very nice OS javascript on the fly form validation and works very well.
    Filefeed.net - Image Hosting -

Posting Permissions

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