Solved

Select / Drodown button display issue

Posted on 2008-06-23
9
256 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
Industry Leaders: 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
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 21852709
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anyone familiar with PhotoSwipe? 3 44
CSS question 4 57
isNaN issue on the Table input text 2 42
Presenting my portfolio on the web? 11 53
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

710 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