Solved

Select / Drodown button display issue

Posted on 2008-06-23
9
261 Views
Last Modified: 2011-09-20
Dear Experts,

In the following situation (see code).

I want the unexpanded dropdown to be limited to 50px. However, when the user click on the drop down I want the options to be display at its full length. How do you do that?



<SELECT Width="50px" style="width: 50px;">
<OPTION value='1'>i like cookie and cream ice cream</option>
<OPTION value='2'>candy apple is very yummie</option>
</SELECT>

Open in new window

0
Comment
Question by:jsissopainful
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 42

Assisted Solution

by:David S.
David S. earned 100 total points
ID: 21852638
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 100 total points
ID: 21852667
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dropdown with Tooltips</title>
<style>
#tooltip {
  position: absolute;
  display:none;
  padding:1px 2px 1px 2px;
  border: 1px solid black;
  background-color:#FFFF99;
}
.dropDownWidth{
 width:60px;
}
</style>
<script language="javascript" type="text/javascript">
// This function checks the mouse event
function checkEvent(e) {
 if (!e) var e = window.event;
 if (e.target) targ = e.target;
 else if (e.srcElement) targ = e.srcElement;
 showHideToolTip(targ, e, e.type)
}
// This function shows/hides the tooltip
function showHideToolTip (theDropDown, e, eType)
{
 var toolTipObj = new Object();
 toolTipObj = document.getElementById("tooltip");
 toolTipObj.innerHTML = theDropDown.options[theDropDown.selectedIndex].text;
 if(eType == "mouseout"){
  toolTipObj.style.display = "none";
   } else
 {
  toolTipObj.style.display = "inline";
  toolTipObj.style.top = e.y + 15;
  toolTipObj.style.left = e.x + 10;
 }
}
</script>
</head>
<body>
<div id="tooltip"></div>
<select id="dropDown1" class="dropDownWidth" onMouseOver="checkEvent(this.event);" onMouseOut="checkEvent(this.event);" onMouseMove="checkEvent(this.event);">
<OPTION value='1'>i like cookie and cream ice cream</option>
<OPTION value='2'>candy apple is very yummie</option>
</select>
</body>
</html>
0
 

Author Comment

by:jsissopainful
ID: 21852674
Ouchy thanks .. it is as I feared :(
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jsissopainful
ID: 21852675
any ways to do this without javascript?
0
 
LVL 18

Assisted Solution

by:Rartemass
Rartemass earned 100 total points
ID: 21852690
CSS does this the best.
Go to: www.alistapart.com
This site has heaps of methods and options specific to menus and drop downs. It will even tell you how to get it working in IE6 browsers with javascript.

This link should be similar to what you need.
http://www.alistapart.com/articles/dropdowns/

Basically with CSS you use multilevel lists. Set the width of the first level to 50px.
Then for second level lists set it to a different width.
You can continue having a different width for each level in the menu.

Please post if you have any issues
0
 

Author Comment

by:jsissopainful
ID: 21852732
Dear pratima_mcs,

Thats not what I am looking for :(



Dear Rartemass,

Thats not what I am looking for as well ... also the example in alistapart requires javascript :(
0
 
LVL 18

Expert Comment

by:Rartemass
ID: 21852750
Actually it only requires javascript to work for older browsers such as IE6; and it is only a small amount of scripting.

I understand you want something else though and will keep looking.
0
 
LVL 2

Accepted Solution

by:
jml948 earned 200 total points
ID: 21852832
The only way i can think to do it would be something like this
<html>
<head>
<script type="text/JavaScript" language="JavaScript">
function setWidth( obj, optObj)
{
var fontSize = optObj.style.fontSize.replace("pt","");
var width = (fontSize/1.33) * optObj.text.length;
obj.style.width = width+'px';
}
</script>
</head>
<body>
<select name="list" id="list" style="width:50px; font-size:8pt">
<option style="font-size:8pt" onclick="setWidth(list, this)" value="1">i like cookie and cream ice cream</option>
<option style="font-size:8pt" onclick="setWidth(list, this)" value="2">candy apple is very yummie</option>
</select>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

635 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