I've spent days researching this (including looking at this site) and I don't understand how to do this.
I'm trying to get the JavaScript to validate that something is selected other than the default blank selection.
Every time the code gets to the select list it pops up with the window alert, but does not check if anything has been selected or not. Even if I have selected something the alert message pops up, and then continues the code so other error alerts pop up from fields not being filled out.
I would like for it to know if something is selected. If it is then no error message for it. If there is nothing selected then I would like only this alert message to appear.
Here is the Javascript function that has to do with this list (in the header)
function selectB() {
x = 0;
if (document.getElementById("mSQ").checked) {
x++;
}
if (document.getElementById("pSQ").checked) {
x++;
}
if (document.getElementById("cSQ").checked) {
x++;
}
if (x == 0) {
window.alert('You must select a Security Question');
mSQ.focus();
return false;
}
}
Here is the HTML
<p>Please Select a Security Question from the Drop Down List.<br />
<select name = "Security Question">
<option value = "d" id = "default" ></option>
<option value = "m" id = "mSQ" >What is your Mother's maiden name?</option>
<option value = "p" id = "pSQ" >What is the name of your pet?</option>
<option value = "c" id = "cSQ" >What is your favorite color?</option>
</select></p>
Please help, I've been stuck on this for so long.