Setting a select option to be selected via JavaScript

Hi,

I’m using JavaScript to set the selected option after a form has been generated, and have been using:

$('select',form.itemPull[form.idPrefix + id]).val(value).attr('selected','selected');

(Using jQuery, where form is the DHTMLXForm object, id and value are self explanatory).

However, this doesn’t work if the field is within a fieldset.

Any ideas?

Hi

Correct, fieldset have nested form.
Also this method is not public.

Thanks for the reply.

How should I be setting the selected option then?

bump?

myForm.setItemValue(name,value);

ex:

{type: "select", label: "Format", name: "format", options:[ {text: "AAC", value: "AAC"}, {text: "AC3", value: "AC3", selected: true}, {text: "MP3", value: "MP3"}, {text: "FLAC", value: "FLAC"} }
AC3 will selected by the default,

myForm.setItemValue("format","AAC");

will select AAC