I am building validation for my forms. I have covered the input text fields with the folowing code:
function validateForm_id()
{
var ctrl = document.forms["form1"]["id"];
var x=ctrl.value;
if (x==null || x=="") {
document.getElementById('id').style.backgroundColor="#FFD4D4";
document.getElementById("id").style.borderColor="#FF7A7A";
document.all.id.innerText = "password required";
I would like to validate the value from my select drop down boxes. The values are:
— Select Title —
Mr
Mrs
Ms
I would like the user to not be able to submit if — Title — is the value from the box.
how do i refer to the first value of the dropdownbox in the if (x==null || x=="") of the above code? Here is my dropdown:
<select name="title" onKeydown="Javascript: if (event.keyCode==13) post();" onFocus="validation_title()" onBlur="return validateForm_title()" id="title">
<option>- Title -</option>
<option value="1">Mr</option>
<option value="2">Mrs</option>
<option value="3">Ms</option>
<option value="4">Other</option>
</select> <div align="center" id="title" style="font-size:small; color:#FF0000;"><script type="text/javascript">document.all.title.innerText = " ";</script></div>
You can use the
selectedIndexproperty of<select>to check out that the first index is never selected.