Reputation: 101
I have defined a select(drop down) in my jsp page. When user will select one of these options i want to display some text boxes. I will use jsp tags to display those textboxes. But I don't know how can i get value of select tag in jsp on the same page. Here is my code:
<div class="col2" >
<select class="textbox" id="noo" name="noo" style="margin-top:10px;" required>
<option value="">Select</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<%
int noo=
%>
What should i write after = to get the selected value in variable?
Upvotes: 1
Views: 4381
Reputation: 514
There are two options:
To submit the form and get the attributes in another jsp or servlets and then return the value using the request.setAttribute(). After which you can get the attributes in the jsp part to display
You can use jquery that is get the value of the select tag after an event occurs e.g after selection e.g var data = $('#noo').find(":selected").text(); Then display the data using a class or id selector.e.g $('p').val(data)
Upvotes: 0
Reputation: 243
This is possible if you use JSTL. You would need to add the jstl.jar file to your lib folder but then the selected value in the variable would be obtained using
${param.name}
Upvotes: 1
Reputation: 4490
JSP is a server side language. Whole html code will be generated before it sends a response to web browser.
So If you want to change something with respect to the value selected by user,
Upvotes: 0
Reputation: 361
JSP pages compile at server side not client side. So,its not possible that you select an option value and take action on it. Yes, this similar thing you can do by JQuery or JavaScript.
If you really want to take support of server side code than ajax can help you. Send selected value to servlet by ajax set response in session or request and iterate session or request in jsp .
Upvotes: 0