Forums Register Login

How to display the last item of a select box as default

+Pie Number of slices to send: Send
Hi Ranchers,
Iam using logic iterate tag,using iteration i have to display some items in the select box,
how to display the last item as default value?
(Please let me know whether I have given enough details...)
Thank you in advance,
ramna
+Pie Number of slices to send: Send
If you use Struts tags to display the select box (<html:select> and <html:options> or <html:optionsCollection>) The value that will show as selected is tied to the property of the ActionForm bean specified in the tag. For example, if you specify <html:select property="foo" > and in your Action form, calling getFoo() returns "xyz". The option that will show as selected is the one with value="xyz".

See this link in the JavaRanch Struts FAQ for more details.
[ February 12, 2007: Message edited by: Merrill Higginson ]
+Pie Number of slices to send: Send
Hi Merrill Higginson ,
Iam not using <html:select>,its just select box.
ramna
+Pie Number of slices to send: Send
Hi Merrill Higginson ,
Actually i have two conditions to check for
The List object may contain(A to D alphabets)
1)if the list contains B,it should display B as default
else
the last item of the list.

I could able to display B,if it is in the list ,if not,I couldn't able to display the last item.
+Pie Number of slices to send: Send
I'd suggest you change your JSP so that it does use <html:select>. While there are ways to do it otherwise, it's much easier with the Struts tags.

Since this is a Struts forum, I'm proposing a Struts solution. Since it appears you want a solution using regular HTML and JSP tags, I'm transferring this thread to the JSP forum.
+Pie Number of slices to send: Send
I got blind or what. Is it really something related to Struts? Sorry, I am asking because I am not seeing anything like that in the original post.

[Edited]
Got it. No worries.
[ February 13, 2007: Message edited by: Adeel Ansari ]
+Pie Number of slices to send: Send
 

Originally posted by Merrill Higginson:
I'd suggest you change your JSP so that it does use <html:select>. While there are ways to do it otherwise, it's much easier with the Struts tags.



Thats not true. Why one would start using struts just for this thing?

You can use,
+Pie Number of slices to send: Send
Adeel,

Just a little history:

This was originally posted in the Struts forum. Generally it can be assumed that if someone posts in the Struts forum, their application already has been built around Struts. If one already has a Struts application, it is in fact true that it's easier to use the Struts tags.

As it became clear that Ramna may not be looking for a Struts solution, but simply posted to the wrong forum, I then moved the thread to the JSP forum hoping that one of you friendly and helpful developers who frequent the JSP forum could help Ramna out.

I hope this clarifies it.

Merrill
[ February 13, 2007: Message edited by: Merrill Higginson ]
+Pie Number of slices to send: Send
Even though I'm not a fan of Struts, if your app is already using Struts it's probably best to do things in "the Struts way". Is there a reason you are not wanting to use the Struts tags?

In any case, to take this any further, please show the JSP code that you are using to populate the select element and its options so we can be of help.
+Pie Number of slices to send: Send
Its so confusing. Please let me say it bold to make the thread clear.

   Its Not At All About Struts

Now please proceed.

Thanks.
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1379 times.
Similar Threads
combo box issue in jsp
linking urls using arrays
A question about JComboBox
c:forEach
how to access combo-box value in javascript?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:03:16.