gekoblu wrote:
Hi!, I want to fix via javascript the combo width to a fix value. I'd
like to implement a kind of ALT / TITLE function to show the entire
option when the text is longer than the combo width...
It's possible?!?
You can set the width with CSS, you can set the title attribute as a
property with javascript
:
<html lang="en">
<head>
<title>setting title of select element</title>
<script type="text/javascript">
function setTitleToSelectedText (select) {
if (select.selectedIndex > -1) {
select.title = select.options[select.selectedIndex].text;
}
}
</script>
<style type="text/css">
select {
width: 100px;
}
</style>
</head>
<body>
<form name="formName" action="">
<p>
<select name="select1" onchange="setTitleToSelectedText(this);">
<option>option 1 option 1 option 1</option>
<option>option 2 option 2 option 2</option>
<option>option 3 option 3 option 3</option>
</select>
</p>
<p>
<select name="select2" onchange="setTitleToSelectedText(this);" size="3">
<option>option 1 option 1 option 1</option>
<option>option 2 option 2 option 2</option>
<option>option 3 option 3 option 3</option>
</select>
</p>
</form>
<script type="text/javascript">
setTitleToSelectedText(document.forms.formName.ele ments.select1);
setTitleToSelectedText(document.forms.formName.ele ments.select2);
</script>
</body>
</html>
Note however that IE/Win doesn't support this (title attribute/property
of <select> elements), but Mozilla, Netscape 6/7, Opera 7 do
--
Martin Honnen
http://JavaScript.FAQTs.com/