Hi,
taglib prefix=”s” uri=”/struts-tags”
<s:select list=”” cssStyle=”width:20px;” id=””>
</s:select>
Can I make an s:select list that has static width behave based on the data as follows :
1. When the dropdown is selected, it dynamically increases based on the largest text in the list2. When selected the list goes back to the static width (hiding text if needed).
Well I started with looking at struts but I realized that it was a dead end.
Started two routes as far as javascript is concerned…
1.
Tried getting dynamic tooltip to display the whole text. Wasn’t too successful at this.
Something that nearly worked was to dynamically increase the width when the drop down is selected but i wasn’t able to get it back to the original width after the selection was made
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” onClick=”autoWidth();”>
</s:select>