[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

<select> field in jsp

Posted on 2006-04-19
3
Medium Priority
?
1,368 Views
Last Modified: 2008-03-10
Dear experts

I have a select field and the value of the select field is set in request in (request.getAttribute("stateSel") )and
i am trying to display that value in jsp but its not working. I want the value to be selected "BY default" when the jsp
is opened

here is the code i have


<select name="state" tabindex="7" class="formstyle" onchange="Options();" width="156" style="width:156px" >
                         
                          <option value="<%=(String)request.getAttribute("stateSel")%>" selected="selected"></option>
                       
                        </select>
                         
any help greatly appreciated

thanks
J
0
Comment
Question by:jaggernat
3 Comments
 
LVL 11

Accepted Solution

by:
WelkinMaze earned 1400 total points
ID: 16493801
Hi,

Try this one:

<select name="state" tabindex="7" class="formstyle" onchange="Options();" width="156" style="width:156px" >
                       
                          <option value="<%=(String)request.getAttribute("stateSel")%>" selected><%=(String)request.getAttribute("stateSel")%></option>
                       
                        </select>
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16494800
Make a null check its a better approach.

<%
String state =(String)request.getAttribute("stateSel");
if(state==null)
{
state="";
}
%>

<select name="state" tabindex="7" class="formstyle" onchange="Options();" width="156" style="width:156px" >
                       
                          <option selected value='<%= state%>' ><%=state%></option>
           
</select>

0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 16495980
I think you may have a collection of data to be displayed in the select list box.
If so, this would be closer to your answer.

<select name="state" tabindex="7" class="formstyle" onchange="Options();" width="156" style="width:156px" >
<% for(int i=0; i<list.size(); i++) {
        String opt = (String)list.elementAt(i);
%>
    <option value="<%=opt%>" <%if(((String)request.getAttribute("stateSel")).equalsIgnoreCase(opt)){%>selected<%}%>><%=opt%></option>
<% } %>
</select>

Hope this help.
Sompol
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question