So I've got some <select>
tags that I would like to show the entire contents in IE. I've looked around and found a few fixes, but I don't want to include YUI since I'm already using jQuery elsewhere, and would prefer to keep the selects on the page instead of replacing it with DIVs.
In the code that I've come up with, FF3 works great. In Internet Explorer (6,7,8) the first click on the <select>
flashes the drop down and then it disappears. I've tried focus
and mousedown
in place of the click
event in the code, no success.
If I remove both of the setting of element.css
in autoWidth
the drop downs work as expected, without the bonus of having a nice width. Does anyone know what would cause the setting of the css to make the drop down fail in IE?
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
var count = 0;
autoWidth = function(e) {
$element = $(e.target)
$element.css("width","auto");
if($element.width() < $element.data("originalWidth"))
{
$element.css("width", $element.data("originalCSSWidth"));
}
}
resetWidth = function(e) {
$element = $(e.target)
$element.css("width", $element.data("originalCSSWidth"));
$("#counter").text(++count);
}
recordEvent = function(e) {
$("#event").text($("#event").text() + " " + e.type);
}
dropDownIEWidthFix = function() {
//if($.browser.msie)
//{
$dropDown = $(this);
$dropDown.data("originalWidth", $dropDown.width());
$dropDown.data("originalCSSWidth", $dropDown.css("width"));
$dropDown.blur(recordEvent);
$dropDown.blur(resetWidth);
$dropDown.change(recordEvent);
$dropDown.change(resetWidth);
$dropDown.click(recordEvent);
$dropDown.click(autoWidth);
//}
};
$(function() {
$("select.officeItemList").each(dropDownIEWidthFix);
});
function trackingSelectionChanged(select)
{
$("#event").text($("#event").text() + " inlineOnChange");
}
</script>
</head>
<body>
<div style="overflow:hidden;width:148px;">
<select class="officeItemList" style="width:148px;" onchange="trackingSelectionChanged(this);">
<option value="1">erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf</option>
<option value="3">pencil</option>
<option value="4">ruler</option>
<option value="5">ink</option>
<option value="7">A4 paper</option>
<option value="8">A3 paper</option>
<option value="9">erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf</option>
<option value="10">executive</option>
<option value="11">janitor</option>
<option value="12">developer</option>
</select>
</div>
<div style="overflow:hidden;width:160px;">
<select class="officeItemList" style="width:160px;" onchange="trackingSelectionChanged(this);">
<option value="3">pencil</option>
<option value="4">ruler</option>
<option value="5">ink</option>
<option value="7">A4 paper</option>
<option value="8">A3 paper</option>
<option value="9">erasersdffffffffffeeefefsdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsdfefesf</option>
<option value="10">executive</option>
<option value="11">janitor</option>
<option value="12">developer</option>
</select>
</div>
<div style="overflow:hidden;width:160px;">
<select class="officeItemList" style="width:160px;" onchange="trackingSelectionChanged(this);">
<option value="1">eee</option>
<option value="3">pencil</option>
<option value="4">ruler</option>
<option value="5">ink</option>
<option value="7">A4 paper</option>
<option value="8">A3 paper</option>
<option value="9">ffff</option>
<option value="10">executive</option>
<option value="11">janitor</option>
</select>
</div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
AdjustWidth fired :<span id="counter"></span> times
<div id="event"></div>
</body>