• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Dynamic width of s:select

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can I make an s:select list to have a static width to have the following properties

1. When the dropdown is selected, it dynamically increases based on the largest text in the list
2. When selected the list goes back to the static width.

Thanks !!
JD
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"J D " please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

To be a bit more descriptive -
<td>
<s:select name="" label="" theme="simple" list="" cssStyle="width:20px;"
value="" id="">
</s:select>
</td>

So as you see it has a standard width but can I get the select list to increase width based when I click on the drop down.
 
Sheriff
Posts: 67699
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is <s:select>? It's not a standard tag.

In any case, you can only affect the <select> element via it's HTML attributes and CSS, so this has been moved to the HTML forum.
[ December 07, 2008: Message edited by: Bear Bibeault ]
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
taglib prefix="s" uri="/struts-tags"

I tried the following javascript but it does not reset the width to 20 px once the combo is set
function autoWidth()
{
var maxlength = 0;
var mySelect = document.getElementById('test');
for (var i=0; i<mySelect.options.length;i++)
{
if (mySelect[i].text.length>maxlength)
{
maxlength = mySelect[i].text.length;
}
}
mySelect.style.width = maxlength * 10;
}

<s:select list="" cssStyle="width:20px;" id="test" onKlick="autoWidth();">
</s:select>
 
Bear Bibeault
Sheriff
Posts: 67699
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think width of the select tag depends mostly on the length of the text in your options list
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sri Anand -

That is what happens but the length goes all the way to 100 characters and I don't want a list that wide. Whereas if I set the width to 20 (which is all the space I have) the combo box gets clipped of.

I remember seeing websites where the dropdown is wider and then when the selection is made it narrows down but I don't seem to be lucky enough to find one now.

I even played around with trying to get a dynamic tooltip that would display the whole text, but that was a dead end as far as I know.
 
Sri Anand
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a similar issue i could not get above this problem,
Issue
display seven long meesages in drop down and user needs to select one of them there were lot of fields in teh form and page lay out was messing up because of length of select
solution or work around
i numbered each message and below the select, i put a multi line text box and when ever a particular number is selected in select, the corresponding message of the number is displayed in the text box, thus keeping the size of the select small

its kind of work around i did to get above this problem if you are sucessful in finding better solution let me know
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey !!

Just what I have started with... I don't know of a better workaround, all that I need to make up my mind on now is whether, to have text in a div as label or have a textarea...

I am hoping to find a better solution...

Thanks for your inputs !!
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This issue is now resolved. I had posted my issue in http://www.webdeveloper.com/ to get the solution.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jay Abrahm!
Thanks for the source code you post above. I've been testing it and I found that this doesn't work in IE7 or IE8, but it works fine in Firefox, do you know why ? I need this solution for IE7 or IE8...
Thanks in advance ! Regards !
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic