Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate combo with javascript!!

Status
Not open for further replies.

bugeditor

Technical User
Oct 9, 2001
44
0
0
IN
I have to populate numbers from one to 100 using client side java script in a combo box..i think it is simple..
but iam getting errors ya..anybody please
 
This should get you started. If you have any questions post them here.


<html>
<head>
<title>test</title>
<Script Language=&quot;JavaScript&quot;>
<!--
function insert(nameditem)
{
if (document.frmTest.txt1.value != '' || ' ')
{
var newOption = document.createElement(&quot;OPTION&quot;);
newOption.text = nameditem;
newOption.value = nameditem;
document.frmTest.select1.add(newOption);
document.frmTest.txt1.value = &quot;&quot;;
document.frmTest.txt1.focus();
}
else
{
alert('Please insert a value.');
}
}
function colors(selCol)
{
document.bgColor = selCol;
}
function setNum()
{
for(x=0;x<=100;x++)
{
var newOption = document.createElement(&quot;OPTION&quot;);
newOption.text = x;
newOption.text = x;
document.frmTest.select1.add(newOption);
}
}
//-->
</Script>
</head>
<body>
<Form name=&quot;frmTest&quot;>
<input type=text value='' name=&quot;txt1&quot;>
<input type=button value=insert onclick=&quot;JavaScript:insert(txt1.value);document.frmTest.txt1.focus();&quot;>
     
<INPUT type=&quot;button&quot; value=&quot;100 entries&quot; id=button1 name=button1 onclick=&quot;setNum();&quot;>
<br>
<select name=&quot;select1&quot; onChange=&quot;colors(this.value);document.frmTest.txt1.focus();&quot; STYLE=&quot;WIDTH: 205px;&quot;>
<Option><------Choose Here-------></Option>
</select>
</Form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top