Listbox comparision between single and multi selec

Results 1 to 3 of 3

Thread: Listbox comparision between single and multi selec

  1. #1
    Join Date
    Dec 1969

    Default Listbox comparision between single and multi selec

    Dear all,<BR><BR>I have two listboxes. One is single select (Listbox01) and the other one is multi-select (Listbox02).<BR><BR>I have to write some client-side validation to make sure that the option selected in Listbox01 isn&#039;t reselected in Listbox02.<BR><BR>I can compare the first Listbox02 value with the Listbox01 value but how can I ensure that the subsequent values of Listbox02 aren&#039;t the same as Listbox01 without taking the value out of the list.<BR><BR>Anybody&#039;s help would be much appreciated.<BR><BR>Thanks.

  2. #2
    Join Date
    Dec 1969

    Default Easy enough...

    &#060;FORM ...&#062;<BR>&#060;SELECT Name="list1" onChange="checkLists(this.form);"&#062;<BR>...<BR> &#060;SELECT Name="list2" MULTIPLE onChange="checkLists(this.form);"&#062;<BR>...<BR> &#060;/FORM&#062;<BR><BR>&#060;SCRIPT&#062;<BR>function checkLists(frm)<BR>{<BR> var sel1 = frm.list1;<BR> var sel2 = frm.list2;<BR> var val1 = sel1.options[sel.selectedIndex].value;<BR> for (var i=0; i &#060; sel2.options.length; ++i )<BR> {<BR> var opt2 = sel2.options[i];<BR> if ( opt2.selected && (opt2.value == val1) )<BR> {<BR> alert("You have the same value selected twice.
    "<BR> + "I am deselecting that value from the second list");<BR> opt2.selected = false;<BR> return;<BR> }<BR> } // end of for loop<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR><BR>Untested. Off the top of my head.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Elegant! <eom>


Posting Permissions

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