www.webdeveloper.com
Results 1 to 4 of 4

Thread: can we add new <optgroup> dynamically to dynamically generated <select> box?

  1. #1
    Join Date
    Oct 2004
    Posts
    6

    can we add new <optgroup> dynamically to dynamically generated <select> box?

    How we can set new <optgroup>,its label and <options> under that group to the selection using javascript? I am generating dynamic selection box. I have to add optgroup dynamically to that selection box whenever the user press the button. (add selection). How can i do this? guide me.

    Thanks
    malik.

  2. #2
    Join Date
    Oct 2004
    Posts
    1,118
    Hi,

    Are you having specific problems with <optgroup> or do you need to know how to create any new html tag?

    The html is rendered on your page already. So, in order to display different html like <optgroup> and <options> you have to insert those tags into the existing hmtl or replace some of the existing html, and that requires that you learn about the wonderful world of the DOM.

    Here are some tutorials:

    http://www.quirksmode.org/dom/intro.html
    http://www.howtocreate.co.uk/tutoria...?tut=0&part=24

  3. #3
    Join Date
    Oct 2004
    Posts
    6
    Thanks.

    I wants to add new <select> tag and <optgroup> and <options> under this optgroup optgroup under select. how can i create new optgroup and add it to newly createed select.

    i know how to add options using .options object of select element reference. i don't know how to create new optgroup and how to add it to select.?

    guide me.

    malik.

  4. #4
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,203
    This may or may not help you out


    function create_optgroup(){
    objSelect=document.forms(0).elements(0);
    optGroup = document.createElement('optgroup')
    optGroup.label = "New Group"

    objOption=document.createElement("option")
    objOption.innerHTML = "Sample1"
    objOption.value = "sample1"

    objSelect.appendChild(optGroup)
    optGroup.appendChild(objOption)
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles