Jump to content

drop down list


Matar

Recommended Posts

hi i write this code form drop down list this code prevent the user from selecting the same value on 2 list so there are 2 list and there option the same both have 4values red,green,blue,yellowwhen the user choose red from the first list in the second list the red value will hide i need to modfiy this code to work with 4 list this the code

<script LANGUAGE="JavaScript">var OptLstTxt = new Array;var OptLstVal = new Array;var OptLen = 0;function NoDupl(SelObjFrom, SelObjTo) {var OldToVal = SelObjTo.options[selObjTo.selectedIndex].value;if (OptLen == 0) {OptLen = SelObjFrom.length;for (var i = 1; i < OptLen; i++) {OptLstTxt = SelObjFrom.options.text;OptLstVal = SelObjFrom.options.value;  }}var j = 1;for (var i = 1; i < OptLen; i++) {if (OptLstVal != SelObjFrom.options[selObjFrom.selectedIndex].value) {if (j == SelObjTo.length) {SelObjTo.options[j] = new Option(OptLstTxt);}else {SelObjTo.options[j].text = OptLstTxt;}SelObjTo.options[j].value = OptLstVal;if (OptLstVal == OldToVal) {SelObjTo.selectedIndex = j;}j++;  }}if (SelObjTo.length > j)SelObjTo.options[(SelObjTo.length - 1)] = null;}//  End --></script>Try to select the same color:<br><select name="Color_1" onChange="NoDupl(this,document.form.Color_2)"><option value='Red'>Red</option><option value='yellow'>Yellow</option><option value='Green'>Green</option><option value='Blue'>Blue</option></select><select name="Color_2" onChange="NoDupl(this,document.form.Color_1)"><option value='Red'>Red</option><option value='yellow'>Yellow</option><option value='Green'>Green</option><option value='Blue'>Blue</option></select>
how can do it ?? :)
Link to comment
Share on other sites

Hope this helps :)

<head><script LANGUAGE="JavaScript">function NoDupl(formValue,formId){  if (formId=="Color_1")  {    document.forms['myform'].Color_2.options[formValue] = null;  }  else  {    document.forms['myform'].Color_1.options[formValue] = null;  }}</script></head><body>Try to select the same color:<br><form name="myform"><select id="Color_1" onChange="NoDupl(this.selectedIndex,this.id)"><option value='Red'>Red</option><option value='yellow'>Yellow</option><option value='Green'>Green</option><option value='Blue'>Blue</option></select><select id="Color_2" onChange="NoDupl(this.selectedIndex,this.id)"><option value='Red'>Red</option><option value='yellow'>Yellow</option><option value='Green'>Green</option><option value='Blue'>Blue</option></select></form></body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...