#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171

    Jquery not working.


    Hi the code above alerts the length of the input (if under 2), but does not change the border color. What am I doing wrong?

    Thanks
    Code:
    <input id="firstname" type="text" onblur="check_validate('form_2', 'paypal_2',2);" 
    name="firstname" >
    javascript Code:
    <script>
    function check_validate(formName, div_id, pid)
    	{
    		var firstname = document.forms[formName].elements["firstname"].value;
    		var len = firstname.length;
    		if(len<2)
    			{
    				alert(len);
    				$("#firstname").css("border-bottom-color", "#ff0000");
    			}
    	}
    </script>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,158
    Rep Power
    183
    Originally Posted by zxcvbnm
    Hi the code above alerts the length of the input (if under 2), but does not change the border color. What am I doing wrong?

    Thanks
    Code:
    <input id="firstname" type="text" onblur="check_validate('form_2', 'paypal_2',2);" 
    name="firstname" >
    javascript Code:
    <script>
    function check_validate(formName, div_id, pid)
    	{
    		var firstname = document.forms[formName].elements["firstname"].value;
    		var len = firstname.length;
    		if(len<2)
    			{
    				alert(len);
    				$("#firstname").css("border-bottom-color", "#ff0000");
    			}
    	}
    </script>
    Didn't really alter your code and it works fine for me. I just added your input inside a form tag with the name of "form_2"; so I am not sure if you had that missing or what.
    Code:
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
    function check_validate(formName, div_id, pid)
    	{
    		var firstname = document.forms[formName].elements["firstname"].value;
    		var len = firstname.length;
    		if(len<2)
    			{
    				alert(len);
    				$("#firstname").css("border-bottom-color", "#ff0000");
    			}
    	}
    </script>
    
    <form name="form_2">
    <input id="firstname" type="text" onblur="check_validate('form_2', 'paypal_2',2);" 
    name="firstname" >
    </form>

IMN logo majestic logo threadwatch logo seochat tools logo