I have a drop down menu which fills with some doc names. Now when a person selects a document it calls onDocumentChange() method.
To fill the drop down menu i receive a object called result which is a list of doc objects from server.
<select id="documentSelect" onChange="onDocumentChange()">
<c:forEach items="${results}" var="result">
<option id="${result.getDocDisplayURL()}"><c:out value="${result.getDocFn()}"/></option>
</c:forEach>
</select>
Till this point it is strainght forward.
Now this doc object has some other attributes called date and time. Now when the user clicks any item from drop down menu i want to send that particular items time and date attributes to onDocumentChange() method. How can i do that.
I am guessing something like this
<select id="documentSelect" onChange="**onDocumentChange(result.date, result.time)**">
<c:forEach items="${results}" var="result">
<option id="${result.getDoc()}"><c:out value="${result.getText()}"/></option>
</c:forEach>
</select>
Thanks
You seem to be thinking that JavaScript runs together with Java/JSP. This is untrue. Java/JSP produces HTML and JavaScript is part of that HTML and works on the HTML DOM tree only. You need to make sure that your Java/JSP code produces HTML code containing exactly the information JavaScript needs to access. You can let Java/JSP print those variables as an attribute of a HTML element, like
<option>in your case. You can use customdata-*attributes in HTML to append custom attributes.You can get the currently selected
<option>element in JavaScript as followsYou only need to change the
onchangehandler to pass the HTML<select>element itselfwith
By the way, why are you using separate properties for date and time instead of a single
java.util.Dateproperty? There’s something wrong in the model design.