Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dojo

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>
        </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?

like image 763
Nick Foote Avatar asked Dec 07 '22 23:12

Nick Foote


1 Answers

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

dijit.byId('qualification').attr('displayedValue')
like image 85
Andrei Avatar answered Jan 03 '23 13:01

Andrei