tags:

views:

48

answers:

2

why this code is not working

    var name = $("#name").val();    
    var email = $("#email").val();
    var web = $("#web").val();
    var comment = $("#comment").val();


    if(name.length < 5){
        $("#name").css("border-color","red");
    } elseif (email.length < 5) {
        $("#email").css("border-color","red");
    } elseif (web.length < 5) {
        $("#web").css("border-color","red");
    } elseif (comment.length < 10) {
        $("#comment").css("border-color","red");         
    }else{

alert('ok');

}

and each val for one like this <input id="name" type="text" size="24" />

+5  A: 

In javascript your elseif needs to be else if, like this:

if(name.length < 5) {
    $("#name").css("border-color","red");
} else if (email.length < 5) {
    $("#email").css("border-color","red");
} else if (web.length < 5) {
    $("#web").css("border-color","red");
} else if (comment.length < 10) {
    $("#comment").css("border-color","red");         
} else {
    alert('ok');
}
Nick Craver
oh my god but phpDesigner 7 write it elseif
moustafa
+1  A: 

The question wasn't all too clear about what the actual problem was but I will mention that borders have more than just a color when defining the CSS--the shorthand is like this:

border: [size] [style] [color];

So if your elements didn't originally have a border thickness/style you might not actually see anything show up when you set the color to red.

Give this a shot:

$("#name").css("border", "2px solid red");
nvuono