Dan G. Switzer, II wrote:
I don't know how to change the selected item in a selectbox. I tried
this but it doesn't work as expected.

HTML code:
=========
<select id="id_cliente" name="cliente" size="1">
   <option value="" selected="selected">---------</option>
   <option value="1">First</option>
   <option value="2">Second</option>
</select>

javascript code:
============
var cliente = 2;
$('#id_cliente:nth-child(cliente)').attr('selected','selected');

any ideas?

Using my Field plug-in (http://jquery.com/plugins/project/field) you could
do:

$("#id_cliente").setValue("2");

The big benefit to using my Field plug-in is that you can change the form
field from a select box to a checkbox or radio element and you would not
have to refactor code that grabs/sets the value of the field.

-Dan

Dan, that truly is an advantage. But I was of the opinion, that val() works with selects and radios as well, thus the refactoring possibility exists for core jQuery as well (of course I don't want people to stay away from your plugin by saying that).

Another question (Mike, Dan?). What are the differences between form and field plugin?


--Klaus

Reply via email to