Link to home
Start Free TrialLog in
Avatar of Sneha Raju
Sneha Raju

asked on

Need to retain the drop down value after submitting the form

I have a jsp page which contain drop downs and two buttons. One button for Upload and other is Run button. I want to retain the value of drop downs even after the Upload is clicked and submitted the form so that the same values should pass for Run button . I used the below code.

<select name="riskType" class="filter_smalltext" onchange="regAuthChange();">
                                          <!-- <option value=0>Select...</option>
                                          <option value="CR">CR</option>
                                          <option value="MR">MR</option>
                                          <option value="BOTH">Both</option> -->
                                          <option value="" selected="selected">Choose One</option>
                                          <option value="<%if(request.getParameter("riskType").equals("CR")) {out.println('selected="selected"'); } %>">CR</option>
                                          <option value="<%if(request.getParameter("riskType").equals("MR")) {out.println('selected="selected"'); } %>">MR</option>
                                          <option value="<%if(request.getParameter("riskType").equals("BOTH")) {out.println('selected="selected"'); } %>">BOTH</option>
                              </select></td>



But i am getting this error :
jv_allocation_process.jsp:16:18: Error in "jv_allocation_process.jsp" at line 401: Invalid character constant
<%@ include file="templates/jv_allocation_process.jsp" %>
                 ^-----------------------------------^

        at weblogic.servlet.jsp.JavelinxJSPStub.reportCompilationErrorIfNeccessary(JavelinxJSPStub.java:247)
        at weblogic.servlet.jsp.JavelinxJSPStub.compilePage0(JavelinxJSPStub.java:183)
        at weblogic.servlet.jsp.JavelinxJSPStub.access$000(JavelinxJSPStub.java:50)
        at weblogic.servlet.jsp.JavelinxJSPStub$1.run(JavelinxJSPStub.java:111)
        at java.security.AccessController.doPrivileged(Native Method)
        Truncated. see log file for complete stacktrace
>
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Probably you have double quotes inside the string. Escape them first and then retry to run the code.
Just look close in what HTML you get with this:

<option value="<%if(request.getParameter("riskType").equals("CR")) {out.println('selected="selected"'); } %>">CR</option>
<option value="<%if(request.getParameter("riskType").equals("MR")) {out.println('selected="selected"'); } %>">MR</option>
<option value="<%if(request.getParameter("riskType").equals("BOTH")) {out.println('selected="selected"'); } %>">BOTH</option>

Open in new window


You get wrong HTML with unclosed quote. You have to do:
<option value="CR" <%if(request.getParameter("riskType").equals("CR")) {out.println('selected="selected"'); } %>">CR</option>
<option value="MR" <%if(request.getParameter("riskType").equals("MR")) {out.println('selected="selected"'); } %>">MR</option>
<option value="BOTH" <%if(request.getParameter("riskType").equals("BOTH")) {out.println('selected="selected"'); } %>">BOTH</option>

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.