How to get option text from dijit.form.Select?
I have 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> </c:choose> </c:forEach> </select> Then some javascript that I am trying to use to set some text in the TEXT of the parameter selected from the selection window;
function checkForPHD() { dojo.byId('clazzPHDMessage').innerHTML = dojo.byId('qualification') .attr('displayedValue'); } I would read that .attr ('displayValue') was supposed to get the text from the selected parameter in dijit.form.Select, but that doesn't seem to be so much? .Attr ('value') got these values, but do I need a TEXT?
It looks like you want innerHTML of the currently selected parameter ( <option>THIS TEXT??</option> ). I think this should do the trick. Flip all selection options with getOptions and find the selected one, then return its innerHTML. I do not know if the dijit.form.Select property has a selectedIndex property, but that also helped.
function getSelectedText() { dojo.foreach(dijit.byId("qualification").getOptions(), function(opt, i) { if (opt.selected) { return opt.innerHTML; } }); } You can try the code snippet below
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>