Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2006, 11:44 AM   PM User | #1
vkkumar
New to the CF scene

 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
vkkumar is an unknown quantity at this point
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 . . .

vkkumar is offline   Reply With Quote
Old 09-02-2006, 12:27 PM   PM User | #2
mic2100
Regular Coder

 
mic2100's Avatar
 
Join Date: Feb 2006
Location: Scunthorpe
Posts: 562
Thanks: 15
Thanked 28 Times in 27 Posts
mic2100 is on a distinguished road
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
mic2100 is offline   Reply With Quote
Old 09-02-2006, 02:50 PM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:51 AM.


Advertisement
Log in to turn off these ads.