tags:

views:

47

answers:

6

my javascript-

function validate_loginform(loginform) 
{
var uid = loginform.uid.value;
var pass = loginform.pass.value;
if(uid == "") 
  {

    color('uid');       
    return false;
  }
if(pass == 0) 
  {
    color('pass');
    return false;
  }

return true;

}

function color(traget)
{
var targetbox = document.getElementById(target);
targetbox.style.backgroundColor="red";
}

but background color is not getting changed even it is not returning fasle value. if I remove the color('uid'); nad put alert("user name required"); then this script is working fine.Whats wrong?
it backgroundColor in actual program I just missed it here only

A: 

You've spelt target wrong in your function header and background wrong in the last line of the function.

dannybolabo
its backgroundColor in actual program I just missed it here only
amanda
+1  A: 

Typo?

backgroungColor
         ^

Update

Typo?

function color(traget)
               ^^^^^^
{
var targetbox = document.getElementById(target);

Seriously, actual code does matter.

Álvaro G. Vicario
its backgroundColor in actual program I just missed it here only
amanda
A: 

just remove the single quote (') from color('uid')

and write it as color(uid);
It's supposed to be a string there. <edit>S</edit>He's using getElementById() to retrieve the element.
dannybolabo
+1  A: 

With jQuery you could try this:

 $("#textbox").css("background-color", "red");
Maciej Kucharz
A: 

hey guy,

Beware your spelling. It should be "target", not "traget".

function color(traget)

ppshein
+1  A: 

dont call color function, change color inside if condition like-

if(uid == "") 
  {     
    //alert("You must enter User ID.","error");
    loginform.uid.style.borderColor='red';
    loginform.uid.focus();
    return false;
  }
nectar