Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2011, 10:33 AM   PM User | #1
praveen.2
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
praveen.2 is an unknown quantity at this point
Title to Option Tag in Select Box

How to add title to options in Select box , where the options are generated from the data base.
Any idea
praveen.2 is offline   Reply With Quote
Old 09-13-2011, 12:35 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
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
Code:
// 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;
}
devnull69 is offline   Reply With Quote
Old 09-13-2011, 12:36 PM   PM User | #3
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 143
Thanks: 3
Thanked 38 Times in 38 Posts
niralsoni is an unknown quantity at this point
Did you tried this one ??

Code:
<SELECT>
	<OPTION TITLE="Description of the option-1">Option 1
	<OPTION TITLE="Description of the option-2">Option 2
</SELECT>
Thanks & Regards,
niralsoni is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Advertisement
Log in to turn off these ads.