View Full Version : Title to Option Tag in Select Box

09-13-2011, 11:33 AM
How to add title to options in Select box , where the options are generated from the data base.
Any idea

09-13-2011, 01:35 PM
So when you create the options in the first place (using PHP or whatever?) you can just add a title attribute to each option.

If you want to add a title attribute using Javascript after the select box has been created, you can use the getElementsByTagName('option') collection of the select box like that

// get the select box named "myselect"
var mySelect = document.getElementsByName('myselect')[0];
// get all its options
var theOptions = mySelect.getElementsByTagName('option');
for(i=0; i<theOptions.length; i++) {
theOptions[i].title = 'This is title #' + i;

09-13-2011, 01:36 PM
Did you tried this one ??

<OPTION TITLE="Description of the option-1">Option 1
<OPTION TITLE="Description of the option-2">Option 2

Thanks & Regards,