Select to view content in your preferred language

Get "Value" from Dijit option, Yeah Right...

2151
11
08-10-2010 01:07 PM
KeithSandell
Regular Contributor
Once again I have spent too much time working on this to feel intelligent any longer.

I've implemented a dijit.form.ComboBox, followed by a dijit.formButton:

The idea here is after the user selects a "displayed value" in the combobox, they click the button and fire off a function that does something based on the "value" of the selected item (<option value="someValue">).

I can get the "displayedValue" all day long and have found many ways to do that, but I simply cannot get inside the option to get the value of its attribute "value."

I've read more dijit and dojo reference than I care to admit and have tried everything I can find on the web, but to no avail.

It is kicking my @$$.

Please help!!

Thanks a million.

function getData(){
var selectedVal =  {can't figure this part out};
if (selectedVal == "expired") {
do this;}
else if (selectedVal == "4") {
do this;}
else if (selectedVal == "future") {
do this;}


<div id="dropDown">
<select dojoType="dijit.form.ComboBox" id="selBox" class="dropSlam" value=" Select...">
        
<option value="expired"> Alex</option>
<option value="expired"> Bonnie</option>
<option value="4"> Colin</option>
<option value="future"> Danielle</option>
<option value="future"> Earl</option>
<option value="future"> Fiona</option>
<option value="future"> Gaston</option>
<option value="future"> Hermine</option>
<option value="future"> Igor</option>
<option value="future"> Julia</option>
<option value="future"> Karl</option>
<option value="future"> Lisa</option>
<option value="future"> Matthew</option>
<option value="future"> Nicole</option>
<option value="future"> Otto</option>
<option value="future"> Paula</option>
<option value="future"> Richard</option>
<option value="future"> Shary</option>
<option value="future"> Tomas</option>
<option value="future"> Virginie</option>
<option value="future"> Walter</option>

</select>
</div>

<div>
<button dojoType="dijit.form.Button" type="button" onClick="getData();">Retrieve Data
</button>
</div>
0 Kudos
11 Replies
KeithSandell
Regular Contributor
You have to be careful when you declarativily...Hope this helps.


Thanks for the info. I'll keep this in mind if I run into a situation where a declarative implementation is best.

But for the time being I have kinda fallen for implementing them progromatically. It keeps the HTML to a minimum and since my lists are fairly large I like using the json becuase I can keep it in a seperate js file.
0 Kudos
MichaelGaigg
Esri Contributor
Get the selected item from the onChange event

   this.reportsDropdown = new ComboBox({
    store: _this.reportsStore,
    id: "cboReports",
    name: "cboReports",
    disabled: false,
    searchAttr: "label",
    onChange: this.reportsChangedEventHandler
   }, this.cboReports);

  reportsChangedEventHandler: function() {
   var report = this.item;
   console.log("Report selected: " + report.value);
   topic.publish("/Reports/changed", { report: report });
  }
0 Kudos