I have the following JSP code for a select statement pulling a list of names stored in a database as nameIDs and names. The drop down shows the names (not the ids)
<select id="name" name="name" onchange="updateName(value)">
<option/>
<c:forEach items="${nameForm.nameList}" var="val">
<option ${nameForm.name eq val.nameId?'selected':''}
value="<c:out value="${val.nameId}"/>">
<c:out value="${val.name}"/>
</option>
</c:forEach>
</select>
I'd like the updateName function to retrieve the value of the selected name. What the code below does is get the nameID not the value. I am not sure why value is returning an ID I am assuming val.nameId
instead of the name selected in the list val.name
function updateName($1){
alert($1);
}
same thing if I use document.getElementById....
And if you change this:
Into this:
Update
How about something like this: http://jsfiddle.net/robertrozas/y8e4B/