• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript Question - Multiple Select Box

Superwormy

Golden Member
Aight, I have a multiple select box:

<select name="category[]" multiple="multiple" size="5">
<option value="1">numberone</option>
<option value="2">nubmertwo</option>
<optoin value="3">numberthree</option>

</select>

Now, I want to test with javascirpt to make sure that NEITHER 1 or 3 are selected. I know I can refer to it like by .value, but it only gives me the first selected option then... how to I check the rest...?

Sorry for the newb question, I'm a PHP kinda guy, me no like Javascirpt 🙂
 
Something like:

if (category.options[0].selected && category.options[2].selected) {
alert("You fool! You can't select number one and three at the same time!");
category.options[0].selected == false;
category.options[2].selected == false;
}
 
OK but then if the order of things in the selectbox changes, it'll break.

I need to have it testing the values of the selected objects I guess... does that make sense?
 
Yes. You'll have to loop through the options property array of the select box, and get the value property for each element and see what value it is.
 
Back
Top