Jump to content

option selection comparison


hoachen

Recommended Posts

I have three different name for the option selection but have the same items on this option. The code below is to compare each selection that the user selected if they select one of the option are the same it will prompt them can't to select the same item. But unfortunately, the code below also check with "select One" listed on first of all three option selection. My question is how do i skip the first option on the three option selection?<Select name="currState1"><option> Select here </option> <option> item 1</option> <option> item 2</option> <option> item 3</option> </select><Select name="currState2"><option> Select here </option> <option> item 1</option> <option> item 2</option> <option> item 3</option> </select><Select name="currState3"><option> Select here </option> <option> item 1</option> <option> item 2</option> <option> item 3</option> </select> if (form.currState1.options[form.currState1.selectedIndex].value == form.currState2.options[form.currState2.selectedIndex].value) { alert('Please select different choice 1 or choice 2'); } else if (form.currState1.options[form.currState1.selectedIndex].value == form.currState3.options[form.currState3.selectedIndex].value)

Link to comment
Share on other sites

If you want to skip over an element... just include a comparison that checks if the selectedIndex is equal to the index of the element you want to skip... or the other way around, if you want to skip the element at the beginning, just make sure the selectedIndex is greater than that of the first element...

Link to comment
Share on other sites

How far is your form going up to? If you're having more than say, three select boxes, it may be worth holding the chosen numbers into an array (select 1 = 0, select 2 = 1, select 3 = 2 etc etc), and querying that at the end. You can always then checkif(selectBox[x] == 0) skip:)

Link to comment
Share on other sites

My question is how do i skip the first option on the three option selection?
Create Dropdown as<Select Name="Drd1"> <Option Value="0">Select </Option> <Option Value="1">Item 1</Option> <Option Value="2">Item 2</Option> <Option Value="3">Item 3</Option></Select>then in the script u can checkif((form.Drd1.value == form.Drd2.value) && (form.Drd1.value != 0)){ alert('you can't select same');}
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...