I've a code like this:
<select name="aa">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
There is a way to stop opening select of all my form and make show only first select in this example only a?
Thanks in advance ciao h
remove all other options with the :gt(0)
filter (0)
is the index like this:
$("select[name='aa'] option:gt(0)").remove();
or disable them like this:
$("select[name='aa'] option:gt(0)").attr("disabled", "disabled");
and select an item with the :eq(0)
filter (0)
is the index like this:
$("select[name='aa'] option:eq(0)").attr("selected", "selected");
the reverse can be done with a :not
filter:
$("select[name='aa'] :not(option:gt(0))").attr("disabled", "disabled");
or a :lt
filter:
$("select[name='aa'] option:lt(1)").attr("disabled", "disabled");
just assign an empty string .attr("disabled", "");
or .attr("selected", "");
to remove an attribute setting.
fiddle here
to flip/flop values I think you need a second (hidden) select:
fiddle here
// hide items
var src = $("select[name='aa'] option:eq(0)");
var tar = $("select[name='ab']").hide();
tar.append(src.clone())
src.remove();
//reshow items:
src = $("select[name='ab'] option:eq(0)");
tar = $("select[name='aa']")
tar.prepend(src.clone())
src.remove();
you can do this:
$("select[name='aa']").val($("select[name='aa'] option:first").val());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With