Se si dispone di codice HTML in questo modo, per esempio:
<select id='myselect'>
<option value='1'>A</option>
<option value='2'>B</option>
<option value='3'>C</option>
<option value='4'>D</option>
</select>
<input type='hidden' id='myhidden' value=''>
Tutto quello che dovete fare è bind a function to the change
event of the select, e fare quello che serve c'è:
<script type='text/javascript'>
$(function() {
$('#myselect').change(function() {
// if changed to, for example, the last option, then
// $(this).find('option:selected').text() == D
// $(this).val() == 4
// get whatever value you want into a variable
var x = $(this).val();
// and update the hidden input's value
$('#myhidden').val(x);
});
});
</script>
Tutto considerato, se hai intenzione di fare un sacco di programmazione jQuery, hai sempre il documentation aperto. È molto facile trovare quello che ti serve se gli dai un'opportunità.
fonte
2009-05-02 21:45:27
le "nuove risposte sono state pubblicate" sembravano aver fallito su tutti noi, lol –