hoachen Posted March 7, 2006 Share Posted March 7, 2006 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 More sharing options...
sbrownii Posted March 7, 2006 Share Posted March 7, 2006 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 More sharing options...
Webworldx Posted March 8, 2006 Share Posted March 8, 2006 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 More sharing options...
Siddhesh Posted March 8, 2006 Share Posted March 8, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now