0

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.

1
  • 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.net I can get value of dropdown which I set its value from javascript. Commented May 11, 2013 at 12:33

3 Answers 3

3

You cannot do that. JavaScript executes on the client side after JSP page is already compiled and sent to the browser as response.

Sign up to request clarification or add additional context in comments.

Comments

2

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 come into picture when your html page loads on browser. So its a compilation error.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.