Problem whit <SELECT>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cristian Martinello

    Problem whit <SELECT>

    How can I add <OPTION> to a tag <SELECT> runtime ?

    the code combo.innerHTML +="<OPTION value='1'>Name</OPTION>" doesn't
    work...


    --
    Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
  • Lasse Reichstein Nielsen

    #2
    Re: Problem whit &lt;SELECT&g t;

    "Cristian Martinello" <cattivofics@ti scali.it> writes:
    [color=blue]
    > How can I add <OPTION> to a tag <SELECT> runtime ?
    >
    > the code combo.innerHTML +="<OPTION value='1'>Name</OPTION>" doesn't
    > work...[/color]

    "Doesn't work" is not very useful as an error message.

    What browsers must it work in? You use the proprietary "innerHTML" .

    I assume "combo" refers to the select element. In that case, this is
    the most portable method:

    combo.options[combo.options.l ength]=new Option("Name"," 1");

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Martin Honnen

      #3
      Re: Problem whit &lt;SELECT&g t;



      Cristian Martinello wrote:
      [color=blue]
      > How can I add <OPTION> to a tag <SELECT> runtime ?
      >
      > the code combo.innerHTML +="<OPTION value='1'>Name</OPTION>" doesn't
      > work...[/color]

      var option = new Option('text', 'value');
      combo.options[combo.options.l ength] = option;

      --

      Martin Honnen


      Comment

      • Yaron Cohen

        #4
        Re: Problem whit &lt;SELECT&g t;


        I works only in IE and I use:


        newOpt = document.create Element("option ");
        newOpt.text="Th is is the new option text"
        newOpt.value="n ewOptionValue"

        document.formNa me.SelectName.o ptions.add(newO pt,2);

        2 is the location of added option on the select.


        <select name="SelectNam e">
        <option value="0" selected>Config uration file</option>
        <option value="1" selected>Test file</option>
        </select>

        Good luck,

        Yaron


        On Wed, 15 Oct 2003 15:15:20 +0000 (UTC), "Cristian Martinello"
        <cattivofics@ti scali.it> wrote:
        [color=blue]
        >How can I add <OPTION> to a tag <SELECT> runtime ?
        >
        >the code combo.innerHTML +="<OPTION value='1'>Name</OPTION>" doesn't
        >work...[/color]

        Comment

        Working...