开发者

How to get option text from a dijit.form.Select?

I have a dijit.form.Select on my page:

<c:set var="qualId" value="${previous.qualification.id}" />
<select id="qualification" name="qualification" dojoType="dijit.form.Select" onchange="checkForPHD()">
    <option value="-1" label="                      "> </option>
    <c:forEach items="${requestScope.qualifications}" var="qualItem">
        <c:choose>
        <c:when test="${qualId eq qualItem.id}">
            <option value="${qualItem.id}" selected = "selected">${qualItem.name}</option>
        </c:when>
        <c:otherwise>
            <option value="${qualItem.id}">${qualItem.name}</option>
        </c:otherwise&开发者_如何学编程gt;
        </c:choose>
    </c:forEach>
</select>

Then some javascript that I'm trying to use to set some text to the TEXT of the option chosen from the select box;

    function checkForPHD() {    
        dojo.byId('clazzPHDMessage').innerHTML = dojo.byId('qualification')
           .attr('displayedValue');
    }

I'd read that the .attr('displayedValue') was suppose to get the text from the selected option in a dijit.form.Select but it doesn't seem to do much? .attr('value') got that values ok but I need the TEXT?


You should use dijit.byId() to get widget instance. Try to use this code to get selected text:

dijit.byId('qualification').attr('displayedValue')


Seems like what you want is the innerHTML of the currently selected option (<option>THIS TEXT??</option>). I think this should do the trick. Loop over all the select's options with getOptions and find the selected one, then return its innerHTML. I don't know if dijit.form.Select has a selectedIndex property, but that would help too.

function getSelectedText() {
  dojo.foreach(dijit.byId("qualification").getOptions(), function(opt, i) {
    if (opt.selected) {
      return opt.innerHTML;
    }
  });
}


You should try to get the selected node first, then get the attribute you want, as follows:

dijit.byId("qualification").getSelected().attr('innerHTML');


You can try the below Code Snip

dijit.registry.byId("regionList").value;

<select name="regionList" id="regionList" data-dojo-id="regionList" data-dojo-type="dijit/form/Select">
<option value="" selected="true">Select LoB</option>
<option value="Asia" >Asia</option>
<option value="Africa" >Africa</option>
</select>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜