Sathish David Kumar N
asked on
how to get all drop down values
Hi ,
I have n number of drop down in my JSp . n value will depends upon the user need (requirement).
i want to get all the drop down values. how to get that ?
I have n number of drop down in my JSp . n value will depends upon the user need (requirement).
i want to get all the drop down values. how to get that ?
div id="headNo1">
<select name="headNo1" id="headNo1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div id="headNo2">
<select name="headNo2" id="headNo2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div id="headNo3">
<select name="headNo3" id="headNo3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
...........
<div id="headNon">
<select name="headNon" id="headNon">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
ASKER
Thanks vr6r ....
may i know what is ix and el
is el means element ?
but if i want to take value with id because ...
some other drop down(element id will differ eg: counId like that ) also there
may i know what is ix and el
is el means element ?
but if i want to take value with id because ...
some other drop down(element id will differ eg: counId like that ) also there
Yes in that example, el is the element referenced in the current loop iteration. Likewise, ix is the index number of that element within the collection of elements returned by the selection, which in this case is all "select" dropdown elements.
Are you asking how you would get the element id, along with the value?
If so, you would do something like this...
Hope this helps.
Are you asking how you would get the element id, along with the value?
If so, you would do something like this...
$('select').each(function(ix,el){
alert($(el).attr('id') + ": " + $(el).val());
});
Hope this helps.
ASKER
no no...
you can check the above code there is 2 diffrent Id there
one is headno(1,2,3...n)
other one xxxx
i want only headno values no other drop down values
div id="headNo1">
<select name="headNo1" id="headNo1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div id="headNo2">
<select name="headNo2" id="headNo2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
<div id="xxxx">
<select name="xxxxx" id="xxxx">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
...........
<div id="headNon">
<select name="headNon" id="headNon">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</div>
you can check the above code there is 2 diffrent Id there
one is headno(1,2,3...n)
other one xxxx
i want only headno values no other drop down values
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Test page : http://jsfiddle.net/31fbvfbo/
$("select[id^=headNo] option").each(function() {
// checking, we alert value and text of option all select with ID like headNo(1,2,...)
alert( $(this).val() + " / " + $(this).text() );
});
ASKER
vr6r its not working in my code ....
leakim971 i think your getting my question wrongly ...
i want the selected values of all drop down
i changed your code like this but not working can you help me
leakim971 i think your getting my question wrongly ...
i want the selected values of all drop down
i changed your code like this but not working can you help me
$("select[id^=headNo] selected ").each(function() {
// checking, we alert value and text of option all select with ID like headNo(1,2,...)
alert( $(this).val() + " / " + $(this).text() );
});
Are you getting an error message at all? The jsfiddle link I included in my example will show you a working version of the code so you can see that it definitely works but it will be hard to tell what the problem is without more info.
If you can post the code you are using so we can take a look I suspect we'll be able to spot the issue pretty quickly.
If you can post the code you are using so we can take a look I suspect we'll be able to spot the issue pretty quickly.
Open in new window
Working example: http://jsfiddle.net/vp20ab