I have the following scenario
<select name="dropdown_Source" onchange="call()">
<% for (int i=0 ; i < a1.length; i++) { if (a1[i]==n ull) break; %>
<option value="<%=a1[i]%>">
<%=a1[i]%>
</option>
<% } %>
</select>
<script>
function call() {
var source = document.forms[0].dropdown_source.value;
// Now this 'source' value i have to pass to jsp function
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
}
</script>
How this source
value should I pass in JSP function?
a.getResult()
- function will return me list of dropdown elements and that list
I have to populate in another <option>
tag.
I have the following scenario
<select name="dropdown_Source" onchange="call()">
<% for (int i=0 ; i < a1.length; i++) { if (a1[i]==n ull) break; %>
<option value="<%=a1[i]%>">
<%=a1[i]%>
</option>
<% } %>
</select>
<script>
function call() {
var source = document.forms[0].dropdown_source.value;
// Now this 'source' value i have to pass to jsp function
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
}
</script>
How this source
value should I pass in JSP function?
a.getResult()
- function will return me list of dropdown elements and that list
I have to populate in another <option>
tag.
- ugly code.. I dont know jsp but I am sure this will not work because jsp server-side javascript client-side.. If you can get dropdown value with jsp do it.. With asp I can get value of dropdown which I set its value from javascript. – Mehmet Commented May 11, 2013 at 12:33
3 Answers
Reset to default 3You cannot do that. JavaScript executes on the client side after JSP page is already piled and sent to the browser as response
.
You can not mix javascript and java code. when you do
<%
Admin a = new Admin(); //this is class defined
a.getResult(source); //but source is not resolved here
%>
This means that code snippet will be processed at server side as this is plain java code.Now variable "source" is not java variable but a javascript variable which will e into picture when your html page loads on browser. So its a pilation error.
The best thing to do here is, once the javascript executes, take that source value and make an AJAX call to your server, process it and send the values back to the client and then populate your dropdown.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742417968a4440111.html
评论列表(0条)