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

    [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.

    function notEmpty(id)
    	var myTextField = document.getElementById(id);
    	if(myTextField.value != "") = ""; 
    	else = "none"; 	
    And in HTML
    <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
    top: 50px; left: 200px;
    Hey ic3d

    This should help you out

    Very nice OS javascript on the fly form validation and works very well. - 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