I’m trying to display a tooltip or hover-text in a list-menu whereby if the user select that value, there will be additional text provided. Is it possible ? As the data is currently stored in a hard-coded array.
Code:
<select name="Interests" id="Interests">
<?php $arr = array('', 'cycling', 'badminton', 'jetskiing', 'ice-skating');
for($i = 0; $i < count($arr); $i++)
{
echo "<option value=\"{$arr[$i]}\" {$selected}>{$arr[$i]}</option>\n";
}
?>
</select>
So if I select the cycling, there should be text appearing on the list-menu. Kindly advise. Thanks!
Here is a possible solution. It uses jQuery, since you can’t use the
title-attribute and you can’t put another child element into theselect-Container, it wouldn’t be valid HTML.See the Demo:
http://jsfiddle.net/DLyMG/
How it works
The trick with this is, to bind the hover
interests.hover. The first function is triggered when you’re over theselect-box, the second is triggered when you leave. I added atimeoutfor this reason: When the user selects something, he moves out of the element (because the list is longer than the element itself). So, when he selects something, he would also trigger themouseoutevent, therefore we have thetimeout.The second thing is to bind the
onchange-event, which is done below. When the user selects a value, the content of the tooltip is changed and you can add any text or HTML as you like.Javascript
CSS
HTML
Note
This needs of course some further improvements. Just an example of how this is possible. And you need to include the jQuery-library in your document, like: