I want to check something server side when I press/select some value in the drop down list. How can I do that ?
I tried as follows :
code : for list
<select id="stream" name="current_session" >
<option value="Winter">Winter</option>
<option value="Monsoon">Monsoon</option>
</select>
code : for button
<form>
<input type="button " name="btn" value ="button">
code : for sriplet
if(request.getParameter("current_session")!=null)
{
system.out.println("helo ur list test is okey ");
}
if(request.getParameter("btn")!=null)
{
system.out.println("helo ur test for button is okey ");
}
note : when im using a button it is working fine when i press the button, but when i select the list its not working.
Attach an on-change listener to your select tag which can fire an ajax request and then you can perform the server-side check and return the response which can be processed on the client-side.
<select id="stream" name="current_session" >
<option value="Winter">Winter</option>
<option value="Monsoon">Monsoon</option>
</select>
<script>
$( "#stream" ).change(function() {
var selectedVal=$("#stream option:selected").val();
$.ajax({
url:"checkonserver.jsp?current_session="+selectedVal,
success:function(msg){
alert(msg);
}
});
});
</script>
checkonserver.jsp
<% if(request.getParameter("current_session").toString().equals("Winter")){%>
It's COLD
<%}else{%>
It's HOT
<%}%>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.