Combobox Validation

Results 1 to 2 of 2

Thread: Combobox Validation

  1. #1
    Join Date
    Dec 1969

    Default Combobox Validation

    I need to validate that a value in a combobox has been chosen on my "registration page".<BR>The validation works fine in IE but skips over it in Netscape.<BR>Heres a piece of the code:<BR><BR> if (form.cboParentLocation.value.length==0) <BR> { <BR> alert("You must select a country from the list");<BR> form.cboParentLocation.focus();<BR> return(false);<BR> } <BR><BR>any ideas would be greatly appreciated,<BR>thanks!

  2. #2
    Join Date
    Dec 1969

    Default There are no comboboxes in HTML...

    A combo box is an MS ActiveX control that allows the user to either select from a dropdown list *or* type in a new value. HTML doesn&#039;t support that.<BR><BR>Having said that...<BR><BR>I presume that what you really mean is an HTML &#060;SELECT&#062; form control. And the problem is that only MSIE allows you to use the .value attribute to get the value of the selected &#060;OPTION&#062; from such a control.<BR><BR>To get a value in a universal manner you need to use:<BR><BR>sel = document.FormName.cboParentLocation;<BR>val = sel.options[ sel.selectedIndex ].value;<BR>if ( val.length == 0 ) ...<BR><BR>But a *better* way to do that is to simply do:<BR><BR>if ( document.FormName.cboParentLocation.selectedIndex == 0 ) ...<BR><BR>Why bother to look at the .value of the selected &#060;OPTION&#062; when all you really need to know is *which* option was selected??<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts