Connecting Tech Pros Worldwide Forums | Help | Site Map

in Select Option entries are cut on the right side if they're too long

Newbie
 
Join Date: Jan 2007
Posts: 4
#1: Jan 5 '07
I use a select box with a fix width (via stylesheet).
So some of the entries are cut on the right side if they're too long.
Is there a way to display them complete like a tool tip on a mouseover?



If I have written code as :-


[HTML]<Select name="selName" style="width: 50">

<OPTION value="">Ball Valve </OPTION>
<OPTION value="">Butterfly Valve </OPTION>
</Select>
[/HTML]
in the browser, in select box it displays Ball Valve in full as written but when some text woth longer length , it cuts it off.

as Butterfly Valve gets only displayed as -- Butterfly v

so , on page display itself....(not any , onChane,, event but onMouseOver..) , i want to show all texts with longer length as ToolTip...

thank u.....
Raghavendra Mahendrakar

b1randon's Avatar
Expert
 
Join Date: Dec 2006
Location: Pittsburgh
Posts: 171
#2: Jan 5 '07

re: in Select Option entries are cut on the right side if they're too long


Quote:

Originally Posted by raghav4web

I use a select box with a fix width (via stylesheet).
So some of the entries are cut on the right side if they're too long.
Is there a way to display them complete like a tool tip on a mouseover?



If I have written code as :-


[HTML]<Select name="selName" style="width: 50">

<OPTION value="">Ball Valve </OPTION>
<OPTION value="">Butterfly Valve </OPTION>
</Select>
[/HTML]
in the browser, in select box it displays Ball Valve in full as written but when some text woth longer length , it cuts it off.

as Butterfly Valve gets only displayed as -- Butterfly v

so , on page display itself....(not any , onChane,, event but onMouseOver..) , i want to show all texts with longer length as ToolTip...

thank u.....
Raghavendra Mahendrakar

I've seen this before and in my app I could definitely use the ability to make that text wrap, if not complete with a tooltip. I hope someone has an answer b/c I don't know. I'm going to do some research though.
b1randon's Avatar
Expert
 
Join Date: Dec 2006
Location: Pittsburgh
Posts: 171
#3: Jan 5 '07

re: in Select Option entries are cut on the right side if they're too long


Quote:

Originally Posted by b1randon

I've seen this before and in my app I could definitely use the ability to make that text wrap, if not complete with a tooltip. I hope someone has an answer b/c I don't know. I'm going to do some research though.

Here's what I'm going to use from now on. It is a script that lets the select box expand an contract.
Expand|Select|Wrap|Line Numbers
  1. var lilPx = "200px"; //size of small select box
  2. var bigPx = "600px"; //size of large select box
  3. var prefix = 'bs';   //prefix used on all select box IDs
  4.  
  5. document.onmouseover = shrinkAll; //handles abandoned selections (no change)
  6.  
  7. function resize(id){
  8.     //get the element in question
  9.     var elem = document.getElementById(id);
  10.  
  11.     //dynamically init/assign the holder variable
  12.     var holder = eval("hold"+id);
  13.  
  14.     //if select not being held open
  15.     if (!holder){
  16.         //go big->small or small -> big
  17.         if(elem.style.width == bigPx)
  18.             elem.style.width = lilPx;
  19.         else    
  20.             elem.style.width = bigPx;
  21.     }else{
  22.         elem.style.width = bigPx;
  23.     }
  24. }
  25.  
  26. function hold(id){
  27.     //swap the hold value, dynamic of course
  28.     eval("hold" + id + " = !hold" + id);
  29.  
  30.     //change size if necessary
  31.     resize(id);
  32. }
  33.  
  34. function shrink(id){
  35.     //get element to shrink
  36.     var elem = document.getElementById(id);
  37.  
  38.     //set width to small
  39.     elem.style.width = lilPx;
  40.  
  41.     //unhold
  42.     eval("hold" + id + " = false");
  43. }
  44.  
  45. function shrinkAll(e){
  46.     //be sure we have the real src, not a bubble or trickle!
  47.     if (!e) var e = window.event;
  48.     var target = (window.event) ? e.srcElement : e.target;
  49.  
  50.     //shrink em all except that one that was the source (possibly)
  51.     var selects = document.getElementsByTagName('select');
  52.     for(i=0; i<selects.length; i++){
  53.         if(selects[i].id.substring(0,prefix.length) == prefix){
  54.  
  55.             //shrink if it wasn't the source (make sure the src isn't parent for <option> in mozilla)
  56.             if(selects[i].id != target.id && selects[i].id != target.parentNode.id ){
  57.                 shrink(selects[i].id);
  58.             }
  59.         }
  60.     }
  61. }
  62.  
[HTML]
<html>
<head><script type="text/javascript" src="script.js"></script></head>
<body onload="" id="body">
<div id="outtie"></div>
<select style="width:200px;" id="bs1" onmouseover="resize(this.id);" onclick="hold(this.id);" onchange="resize(this.id);" onmouseout="resize(this.id);">
<option>00004546353 - MAKROLON TANK TRUCK</option>
<option>00004567435 - 500 BARRELS OF POLYOL 50 KG ea</option>
<option>00056463543 - POLYURETHANE BLEND</option>
<option>00005464354 - 50% ACID SOLUTION</option>
<option>00056875343 - 50 PALLETS OF RANDOM CHEMICALS</option>
</select>
<br />
<select style="width:200px;" id="bs2" onmouseover="resize(this.id);" onclick="hold(this.id);" onchange="resize(this.id);" onmouseout="resize(this.id);">
<option>00004546353 - MAKROLON TANK TRUCK</option>
<option>00004567435 - 500 BARRELS OF POLYOL 50 KG ea</option>
<option>00056463543 - POLYURETHANE BLEND</option>
<option>00005464354 - 50% ACID SOLUTION</option>
<option>00056875343 - 50 PALLETS OF RANDOM CHEMICALS</option>
</select>
</body>
</html>
[/HTML]
Let me know if you have problems implementing it. ;)
Newbie
 
Join Date: Jan 2007
Posts: 4
#4: Jan 8 '07

re: in Select Option entries are cut on the right side if they're too long


Hi,

Thankyou very much for your code. It's very very worthful for me.

But i am experimenting on this way...

If i want to insert an image, after the dropdown option :

[HTML]<H1>DIV with Hidden</H1>
<DIV style="OVERFLOW: hidden; position:relative; overflow-x: hidden; overflow-y: fixed; fixed; visibility:visible; width:200px"><SELECT title=select >
<option selected>Testing Testing </option>
<option title="This text should appear in a tooltip popup, but does not.">Testing </option>
<option>Testing Testing </option>
<option>Testing Testing Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing Testing Testing Testing Testing Testing Testing</option>
<option>Testing </option>
</SELECT>
</DIV>
[/HTML]
It's showing the hidden div tag. After the DIV Tag, how to insert an rollover image, which should look and feel works like a dropdown menu... When i click on the menu arrows, the dropdown menu should be visiable as the normal menu.

Is it possible....

Waiting for ur reply...
b1randon's Avatar
Expert
 
Join Date: Dec 2006
Location: Pittsburgh
Posts: 171
#5: Jan 8 '07

re: in Select Option entries are cut on the right side if they're too long


Quote:

Originally Posted by raghav4web

Hi,

Thankyou very much for your code. It's very very worthful for me.

But i am experimenting on this way...

If i want to insert an image, after the dropdown option :

<H1>DIV with Hidden</H1>
<DIV style="OVERFLOW: hidden; position:relative; overflow-x: hidden; overflow-y: fixed; fixed; visibility:visible; width:200px"><SELECT title=select >
<option selected>Testing Testing </option>
<option title="This text should appear in a tooltip popup, but does not.">Testing </option>
<option>Testing Testing </option>
<option>Testing Testing Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing Testing Testing Testing Testing Testing Testing</option>
<option>Testing </option>
</SELECT>
</DIV>

It's showing the hidden div tag. After the DIV Tag, how to insert an rollover image, which should look and feel works like a dropdown menu... When i click on the menu arrows, the dropdown menu should be visiable as the normal menu.

Is it possible....

Waiting for ur reply...

I'm not really sure what you mean. Do you want replace the select completely or are you trying to build some external controls for it or what?
Newbie
 
Join Date: Jan 2007
Posts: 4
#6: Jan 9 '07

re: in Select Option entries are cut on the right side if they're too long


Hi,

If you see this code

[HTML]<DIV style="OVERFLOW: hidden; position:relative; overflow-x: hidden; overflow-y: fixed; fixed; visibility:visible; width:200px">
<SELECT title=select>
<option selected>Testing Testing </option>
<option>Testing </option>
<option>Testing Testing </option>
<option>Testing Testing Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing </option>
<option>Testing Testing Testing Testing Testing Testing Testing</option>
<option>Testing </option>
</SELECT>
<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','up1.gif',1) "><img src="down1.gif" name="Image1" width="17" height="20" border="0"></a></DIV>
[/HTML]
When i insert the image inside the DIV layer, when i click on the image, the select options should be visiable the option values. And the click function should work through scripts.

How to define that...

waiting for ur reply...



Quote:

Originally Posted by b1randon

I'm not really sure what you mean. Do you want replace the select completely or are you trying to build some external controls for it or what?

Newbie
 
Join Date: Jan 2007
Posts: 4
#7: Jan 9 '07

re: in Select Option entries are cut on the right side if they're too long


Hi,

Thank you very very much for your wonderful script. It's working WOW... I just added DIV layer to fix the width.

[HTML]<DIV style="OVERFLOW: hidden; position:relative; overflow-x: hidden; overflow-y: fixed; fixed; visibility:visible; width:200px">
<select class="dropDownLong" name="cusrDtls_DT_FMT" style="width:200px;" id="bs1" onmouseover="resize(this.id);" onclick="hold(this.id);" onchange="resize(this.id);" onmouseout="resize(this.id);">
<option value="02/" selected>Short Date Format Short Date Format Short Date Format</option>
<option value="03/">Long Date Format</option>
<option>Long Date FormatLong Date Format</option>
<option>Long Date FormatLong Date FormatLong Date FormatLong Date Format</option>
<option>Long Date FormatLong Date FormatLong Date Format</option>
<option>Long Date FormatLong Date Format</option>
<option>Long Date FormatLong Date Format</option>
</select></div>
[/HTML]
But now, whenever i select the menu and using to view UP and DOWN arrows from my keyboard, it's alternatively changing the width of the menu. Why this happening. Is there any way to fix this...

Waiting for your reply.




Quote:

Originally Posted by b1randon

I'm not really sure what you mean. Do you want replace the select completely or are you trying to build some external controls for it or what?

b1randon's Avatar
Expert
 
Join Date: Dec 2006
Location: Pittsburgh
Posts: 171
#8: Jan 9 '07

re: in Select Option entries are cut on the right side if they're too long


Quote:

Originally Posted by raghav4web

Hi,

Thank you very very much for your wonderful script. It's working WOW... I just added DIV layer to fix the width.

<DIV style="OVERFLOW: hidden; position:relative; overflow-x: hidden; overflow-y: fixed; fixed; visibility:visible; width:200px">
<select class="dropDownLong" name="cusrDtls_DT_FMT" style="width:200px;" id="bs1" onmouseover="resize(this.id);" onclick="hold(this.id);" onchange="resize(this.id);" onmouseout="resize(this.id);">
<option value="02/" selected>Short Date Format Short Date Format Short Date Format</option>
<option value="03/">Long Date Format</option>
<option>Long Date FormatLong Date Format</option>
<option>Long Date FormatLong Date FormatLong Date FormatLong Date Format</option>
<option>Long Date FormatLong Date FormatLong Date Format</option>
<option>Long Date FormatLong Date Format</option>
<option>Long Date FormatLong Date Format</option>
</select></div>

But now, whenever i select the menu and using to view UP and DOWN arrows from my keyboard, it's alternatively changing the width of the menu. Why this happening. Is there any way to fix this...

Waiting for your reply.

That is one downside to the behavior I built. It is because I used the onchange event handler and the arrow keys automatically fire onchange. Unfortunately I don't have the time to go digging back through it to improve. You're welcome to have a shot at it yourself. Just post it back here if you figure it out.
Newbie
 
Join Date: Dec 2007
Posts: 1
#9: Dec 24 '07

re: in Select Option entries are cut on the right side if they're too long


Having a couple problems implementing... I'm using this script with some dynamically created results and the first problem I'm having is that the
Expand|Select|Wrap|Line Numbers
  1. document.onmouseover = shrinkAll;
line is grinding the page to a halt, pretty much crashing the browser, as there alot of fields (bout 500)..
Second problem I'm having (once i've commented the mouseover/shrinkAll line)seems to be with the eval function
Expand|Select|Wrap|Line Numbers
  1. var holder = eval("hold"+id);
Even though "bs123" is a valid id on the page it keeps giving me an error message like; "bs123" is undefined

Code obviously works when I don't mix with my own but I'd like to get it too work properly... any insight?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,750
#10: Dec 26 '07

re: in Select Option entries are cut on the right side if they're too long


Quote:

Originally Posted by njcu

Second problem I'm having (once i've commented the mouseover/shrinkAll line)seems to be with the eval function

Expand|Select|Wrap|Line Numbers
  1. var holder = eval("hold"+id);
Even though "bs123" is a valid id on the page it keeps giving me an error message like; "bs123" is undefined

Can you post some of your HTML code? There's no need to use eval for this. You could use something like window["hold" + id].
Reply