Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    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;
    }

  • #3
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    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,


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •