...

View Full Version : Dynamic Number listbox . . . . Help me please



vkkumar
09-02-2006, 11:44 AM
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 . . .

:confused: :confused: :confused:

mic2100
09-02-2006, 12:27 PM
u could use this to create ur dropdown



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

vwphillips
09-02-2006, 02:50 PM
<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum