Merry Christmas all,
What is the code to externally validate a dropdown box?
I am moving my javascript form validation to an external .js page and am
stuck on the listboxes.
The following snippet works fine inside the original page (where "theForm"
is the name of the form & "good" is the name of a specific listbox).
if (theForm.good.selectedIndex == 0)
{ alert("Choose how good you\'ve been this year from the list");
theForm.good.focus();
return (false);
}
In the external .js page I've been playing around with something to this
effect to no avail (where "checkDrop" is the name of the called
function, "s" is a message string, "emptyOK" sets required fields
and "warnEmpty" generates the alert message.):
function checkDrop (theField, s, emptyOK)
{ if(checkDrop.theField.selectedIndex == 0)
return warnEmpty (theField, s);
else return true;
}
The code in the form is:
<select name="good" size="1" onChange="checkDrop(this,sGood,false)">
Note that I'm also generalizing the external .js code to handle all
dropdown boxes.
I've tried various permutations of "checkDrop.theField.selectedIndex"
using "theForm, s, document etc.etc."
Free candy canes to all who reply *wink*
"Santa"