Solved

Select / Drodown button display issue

Posted on 2008-06-23
9
220 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
  • 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
 

Author Comment

by:jsissopainful
ID: 21852675
any ways to do this without javascript?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now