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 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dynamic Number listbox . . . . Help me please

    Hi,

    I am trying to create a dropdown list dynamically, where i want to populate the listbox with numbers 1 to 100.

    I tried writing the code as shown below . . . it is not working.



    var qtEl = document.createElement('select');
    qtEl.setAttribute('name', 'myqty');
    for(var j=1;j<=100;i++) {
    var qtOption=document.createElement('OPTION');
    var qtText=document.createTextNode(j);
    qtOption.appendChild(qtText);
    qtOption.setAttribute('value',j);
    qtEl.appendChild(qtOption);
    }


    Can anyone help me please . . .


  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    u could use this to create ur dropdown

    Code:
    function dropdown()
    {
    	
    	document.write("<select name='lst_numbers'>")
    	
    	for(i=1;i<101;i++)
    	{
    	
    		document.write("<option value=" + i + ">" + i + "</option>")
    	
    	}
    	
    	document.write("</select>")
    
    }
    not the same aas wot u ave used in ur example but it works

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function Populate(id,srt,fin){
     var obj=document.getElementById(id);
     obj.options.length=1; // change this to 0 if prefered
     for (var zxc0=srt;zxc0<=fin;zxc0++){
      obj.options[obj.options.length]=new Option(zxc0,zxc0,true,true);
     }
     obj.selectedIndex=0;
    }
    //-->
    </script></head>
    
    <body>
    <select id="fred" >
    <option >Select</option>
    </select>
    <br>
    <input type="button" name="" value="Populate 1 to 100" onclick="Populate('fred',1,100);">
    <input type="button" name="" value="Populate 50 to 54" onclick="Populate('fred',50,54);">
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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