I am working on this script, and for some reason, it is acting as if fn.style.borderColor always equals #F00. All I want is for the second one to execute if and only if the first if has been executed.
function vfn() {
if (fnl<1){
na.innerHTML= "This field is required.";
fn.style.borderColor="#F00";
}
else if (fn.style.borderColor="#F00" && fnl>1) {
if(lnl>1){
na.innerHTML= "OK";
setTimeout("na.innerHTML = ''",1500)
}
fn.style.borderColor="#0F0";
setTimeout("fn.style.borderColor='';",1500)
}
return false
}
I tried using variables and did something like this, but it didn’t work at all.
var error = 1
if (error = 1) {
alert("error1");
var error = 2
}
else if (error == "2") {
alert("error2")
var error = 1
}
So how can I make this work?
————————————->>EDIT<<————————————
Ok, so I changed it to this
function vfn() {
if (fnl<1){
na.innerHTML= "This field is required.";
fn.style.borderColor="#F00";
}
else if (fn.style.borderColor == "#F00" && fnl>1){
if(lnl>1){
na.innerHTML= "OK";
setTimeout("na.innerHTML = ''",1500)}
fn.style.borderColor="#0F0";
setTimeout("fn.style.borderColor='';",1500)
}
return false}
and what’s happening is that the border color is changed to red when the field is empty, which is what should happen, But when the field is filled in properly, it is SUPPOSED to change to green, then after 1.5 seconds, change back to default, but instead, what actually happens is that it stays red, as if it is ignoring the else if block of code, even though the field is already red (the fn.style.borderColor=”#F00″).
Try to make your else if look like this:
else if (fn.style.borderColor == "rgb(255, 0, 0)" && fnl>1){