I have a small script which checks a text field on a form against values in a select box, then alert either 'Match' if there is a match or 'no match' if there is no match. However, I would like the script to end if the text field is blank.
The code is:
Expand|Select|Wrap|Line Numbers
- function compareID(){
- var idlist = document.getElementById('1stDefinition').options;
- var idinput = document.getElementById('existingid');
- var match = false;
- for (i=0; i<idlist.length; i++) {
- if (idlist[i].value.toLowerCase() == idinput.value.toLowerCase()){ match = true; }
- }
- if (match) { alert("match"); } else {
- alert("no match");
- document.Enrolment.existingid.focus();}
- }
[HTML]<input type="text" name="Users_ID" size="10" maxlength="8" style="text-transform: uppercase" id="existingid" onblur=compareID();>[/HTML]
What seems to happen is, if the text field is clicked into and the left blank - the onblur says 'no match' and puts the cursor back in the text field - what it should do - if the text field is blank on blur then the script should just end.
Suggestions?????