...

View Full Version : object.style isnt working



jcdevelopment
01-28-2009, 03:41 AM
I was trying to change the style of a dropdown menu when a user misses it.

So basically when they submit and the user misses a dropdown i need it to have a "red" border, if possible.

For now i just made the style a large width.. it wont work though. what am i doing wrong?


if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
return false;
document.getElementById("name").style.width="200px";
}
return true;
}

oesxyl
01-28-2009, 04:06 AM
I was trying to change the style of a dropdown menu when a user misses it.

So basically when they submit and the user misses a dropdown i need it to have a "red" border, if possible.

For now i just made the style a large width.. it wont work though. what am i doing wrong?


if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
return false;
document.getElementById("name").style.width="200px";
}
return true;
}


blue line is never executed because of return false:

if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
return false;
document.getElementById("name").style.width="200px";
}
return true;
}


best regards

jcdevelopment
01-28-2009, 04:17 AM
so is there a way around this? Or possibly a way to rewrite this?

oesxyl
01-28-2009, 04:24 AM
so is there a way around this? Or possibly a way to rewrite this?
move return false after document.getElement...


if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
document.getElementById("name").style.width="200px";
return false;
}
return true;
}

I don't know if that is what you want to do but in this case set focus and resize element will be both executed.

best regards

jcdevelopment
01-28-2009, 04:30 AM
See, i tried in the first place, but for some reason it will submit the form. Am i doing something wrong with this.. let me give you the whole code..


<script language="javascript">

function fCheck(formObj){
//alert(formObj.name.value);
if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
document.getElementById("name").style.backgroundColor="#ff0000";
return false;

}

if (formObj.address.value == "null"){
formObj.address.focus();
alert('Please select an option for Address 1');
return false;
}
if (formObj.city.value == "null"){
formObj.city.focus();
alert('Please select an option for City');
return false;
}
if (formObj.state.value == "null"){
formObj.state.focus();
alert('Please select an option for State');
return false;
}
if (formObj.zip.value == "null"){
formObj.zip.focus();
alert('Please select an option for Zip');
return false;
}
return true;
}
</script>

oesxyl
01-28-2009, 04:43 AM
See, i tried in the first place, but for some reason it will submit the form. Am i doing something wrong with this.. let me give you the whole code..


<script language="javascript">

function fCheck(formObj){
//alert(formObj.name.value);
if (formObj.name.value == "null"){
formObj.name.focus();
alert('Please select an option for Name');
document.getElementById("name").style.backgroundColor="#ff0000";
return false;

}

if (formObj.address.value == "null"){
formObj.address.focus();
alert('Please select an option for Address 1');
return false;
}
if (formObj.city.value == "null"){
formObj.city.focus();
alert('Please select an option for City');
return false;
}
if (formObj.state.value == "null"){
formObj.state.focus();
alert('Please select an option for State');
return false;
}
if (formObj.zip.value == "null"){
formObj.zip.focus();
alert('Please select an option for Zip');
return false;
}
return true;
}
</script>
that means formObj.xxxx.value is never null. I would check first formObj to see if is undefined and then test each formObj.xxx.value. For some form elements is possible formObj.xxx to don't have a value for example, I'm not sure, but select don't have.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum