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
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question dynamic options woun't stay open

    I built a script which generates dynamicaly a list according to check boxes checked. The phoney thing is that the list woun't stay open when click the arrow, so I can not select an option... Any ideea?

    PHP Code:
    <html>
    <
    head>
    <
    script>
    function 
    bla(){
    var 
    o1 ='<option>';
    var 
    o2 '</option>';
    var 
    c='';
    var 
    = new Array()
    for(
    i=0;i<document.forms[0].elements['ch'].length;i++){
    a[i] = document.forms[0].elements['ch'][i];
        if(
    a[i].checked == true){b=o1+a[i].value+o2;}
        else{
    b='';}
    c=c+b;
    }
    document.getElementById('sel').innerHTML '<select>'+o1+o2+c+'</select>';
    }
    </script>
    </head>

    <body onclick="bla()">
    <form>
    <input name="ch" type="checkbox" value="one" onclick="bla()">
      one <br>
      <input name="ch" type="checkbox" value="two" onclick="bla()">
      two <br>
      <input name="ch" type="checkbox" value="three" onclick="bla()">
      three <br>
      <input name="ch" type="checkbox" value="four" onclick="bla()">
      four <br>
      <input name="ch" type="checkbox" value="five" onclick="bla()">
      five <br>
    <br>
    <div id="sel">
    </div>
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    innerHTML doesn't actually add new options to a dropdown. you have to manaully add them using the add options method seen here at MSDN

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Oh, but it does... Anyway, I found out what happened. Silly me, I wrote something stupid in body

    <body [b]onclick{/b]...

    I remove the stupidity and It works OK.

    Well yes, maybe is a more correct ideea to build dinamically using createElement()...

    Thus, I am not sure that I can sumbit some values from those options, but I will check it out.

    Tx
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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