i cant understand why this simple function doesnt work in the way i want it to work 🙂
c = document.form.product_catid.selectedIndex;
if (document.form.product_name.value == "" && document.form.product_catid[c].value == "")
{
alert ("Please, define at least product name or product category !");
return false;
}
else if (!(document.form.product_name.value == ""))
{
return true;
}
else if (!(document.form.product_catid[c].value == ""))
{
return true;
}
else
{
alert ("Please, dont define two of them at the same time!");
return false;
}
return true;
all i want is when input with name product_name is filled OR select with name product_catid is selected, the function is returned true, but if none of them or both are defined, i want it to alert two different alerts ) thank you all for the help, i really appreciate it!
Try debugging your case using Chrome Developer Tools, Firebug, or something similar. My suspicion is that you are trying to compare
""andundefinedin thedocument.form.product_catid[c].value == ""clause (this will be the case whenselectedIndexis-1). Try just!document.form.product_catid[c].valueinstead.