I am trying to deselect a select option element with jQuery. Here is my scenario:
I have 3 select options:
[ Select 1 ]
[ Select 2 ]
[ Select 3 ]
Scenario: Select 1 is prefilled with data from an ajax call. So Select 1 has opt 1, opt 2, opt 3, etc.
When you select an option from Select 1, it fills Select 2 with data, and when you select from Select 2 it fills Select 3, and so on.
Depending on what you select, it puts the values from those ":selected" options and apply to a variable called "url".
So in the case that you only select "Select 1":
url = 'search/for/this/select1/'
In th case that you select "Select 1" and "Select 2"
url = 'search/for/this/select1/select2/
And so on.
This is the way im writing the jQuery code:
var url = 'search/for/this';
if(element1.is(':selected')) {
url += element1.val();
// makes url = 'search/for/this/select1val/';
if(element2.is(':selected')) {
url += element1.val();
// makes url = 'search/for/this/select1val/select2val/';
if(element3.is(':selected')) {
url += element1.val();
// makes url = 'search/for/this/selectval1/select2val/select3val/';
}
}
}
The problem is, this requires that I de-select the next options after the previous one was selected, but since there is data that is filled in, it seems to automatically return true when it passes through the ":selected" condition check in the code example above. Any thoughts on how to accomplish this functionality? If I am not making my issue clear. Please requested more details and I will add them in. Thanks -Chris-