Reputation: 33
I have two selects with the same class and differents id. One of them is hidden, but when I'm trying get the value, I only get the value of the first select what I selected. Help please.
HTML
<input id="marcas" name="tipoSearch" type="radio" onclick="opcionSearch(this.id)"><span id="spanmarcas" class="spancat">por Marcas</span>
<input id="categorias" name="tipoSearch" type="radio" onclick="opcionSearch(this.id)"><span id="spancategorias" class="spancat">por Categorías</span>
<select id="selmarcas" class="selbuscar" style="display:none;"></select>
<select id="selcategorias" class="selbuscar" style="display:none;"></select>
<input id="butBuscar" type="button" value="Buscar" disabled="disabled"/>
JAVASCRIPT
function opcionSearch(opcion){
document.getElementById('butBuscar').disabled=false;
if(opcion=='marcas'){
$('input[name=tipoSearch]').show();
$('.selbuscar').prop('disabled', true);
$('.selbuscar').hide();
$('.spancat').show();
$('#'+opcion).hide();
$('#span'+opcion).hide();
$('#sel'+opcion).show();
$('#sel'+opcion).prop('disabled', false);
}
else{
$('input[name=tipoSearch]').show();
$('.selbuscar').prop('disabled', true);
$('.selbuscar').hide();
$('.spancat').show();
$('#'+opcion).hide();
$('#span'+opcion).hide();
$('#sel'+opcion).show();
$('#sel'+opcion).prop('disabled', false);
}
}
$('#butBuscar').click(function(){
var value = $('.selbuscar').val();
alert(value)
});
Upvotes: 0
Views: 36
Reputation: 74
$("select[class^='selbuscar']").click(function(){
var value = $(this).val();
alert(value);
});
Upvotes: 0
Reputation: 73896
You can do this:
$('#butBuscar').click(function () {
$('.selbuscar').each(function () {
var value = $(this).val();
alert(value)
});
});
You can loop through all the selbuscar
drop-downs and then get the selected values of each.
UPDATE
For getting the value of the enabled drop down, you can do this:
$('#butBuscar').click(function () {
var value = $('.selbuscar:enabled').val();
alert(value);
});
Upvotes: 2