Dojo - Setting the ComboBox Default Value
Posted in dojo, autocomplete, ajax Wed, 14 Jun 2006 08:39:00 GMT
Dojo Toolkit's ComboBox doesn't take a default value but one can be written in using JavaScript. The default value in the ComboBox dojoType is lost during onLoad when the dojoType widget is rendered. To get around this we can use JavaScript to fill in the value during dojo.addOnLoad. Here's the relevant JavaScript:
function init() { var mycombobox = dojo.widget.byId('mycombobox'); mycombobox.textInputNode.value = 'Seattle'; } // method 1 dojo.addOnLoad( init ); // method 2 dojo.addOnLoad( function() { init() } )
// won't work b/c you want to send an object // not call a function dojo.addOnLoad( init() );
The HTML:
<input dojoType="ComboBox" id="mycombobox" value="this should never be seen - it is replaced!" dataUrl="comboBoxData.js" style="width: 300px;" name="foo.bar" onValueChanged="setVal2" >
A more detailed example of this technique is available on the wiki at Dojo Toolkit: Setting the Combobox Default Value.
I believe the best way to do it would be
dojo.widget.byId(‘mycombobox’).setValue(‘Seattle’)
Since directly overwriting the textInputNode.value does not notify the ComboBox of the change, and thus doesn’t update it’s internals; this means that if the user does not interact with the ComboBox (which itself calls setValue()) then it will not submit the form properly.
Unfortunately, I was unable to create an account on the Wiki to update that.
If text in the combo box options are different than the actual values, I find it necessary to use:
dojo.widget.byId(‘mycombobox’).setValue(‘Seattle’); dojo.widget.byId(‘mycombobox’).setSelectedValue(5);
(assuming the actual value for Seattle is 5).
how to set the value to filtering select combobox from data base….......