How to add a combo box dynamically at run time in Java
script?
Answers were Sorted based on User's Feedback
Answer / kannappanksk
for (var i=0;i<5;i++)
{
document.forms[0].cmb1.options[i]= new Option("Test"+i,i)
}
| Is This Answer Correct ? | 77 Yes | 35 No |
Answer / thara kv
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
<script>
function add()
{
var tbl = document.getElementById('myTable');
var lastRow = tbl.rows.length;
var row = tbl.insertRow(lastRow);
var m=1;
var cellRightSel = row.insertCell(0);
var sel1 = document.createElement('select');
sel1.name = 'item';
sel1.id='item' ;
sel1.options[0] = new Option('Select An Item', '0');
for(f=0;f<5;f++)
{
var q='item-'+f;
sel1.options[m] = new Option(q,f);
m++
}
cellRightSel.appendChild(sel1);
}
</script>
</head>
<body>
<input type="button" value="ADD" onClick="add()">
<table id="myTable">
</table>
</body>
</html>
| Is This Answer Correct ? | 42 Yes | 15 No |
Answer / dennis
I apologize as I have a question with regards to Answer #1,
does it att a combo box dynamically or a combo box option
dynamically?
| Is This Answer Correct ? | 32 Yes | 18 No |
Answer / augusto vyhmeister
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=windows-1250">
<meta name="generator" content="PSPad editor,
www.pspad.com">
<title></title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function change(currentbox) {
alert('very complex...to understand');
}
function change1()
{
alert('changing...');
son = document.getElementById("combo_0");
son1 = document.getElementById("combo_1");
son2 = document.getElementById("combo_2");
alert(son.value);
if(son.value == '0') //
{
son1.options.length = 0;
son2.options.length = 0;
}
if(son.value == '1') //
{
son1.options.length = 0;
for (var i=0;i<5;i++)
{
son1.options[i]= new Option("Test"+i,i)
}
}
if(son.value == '2') //
{
son1.options.length = 0;
for (var i=0;i<15;i++)
{
son1.options[i]= new Option("Test"+i,i)
}
}
if(son.value == '2') //
{
son1.options.length = 0;
for (var i=0;i<10;i++)
{
son1.options[i]= new Option("Test"+i,i)
}
}
}
</script>
<form>
<select name="combo0" id="combo_0" onChange="change1
(this);" style="width:200px;">
<option value="0">-select-</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<BR><BR>
<select name="combo1" id="combo_1" onChange="change(this)"
style="width:200px;">
<option value="0">-select-</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<BR><BR>
<select name="combo2" id="combo_2" onChange="change(this);"
style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo3" id="combo_3" onChange="change(this);"
style="width:200px;">
<option value="value1"> </option>
</select>
</form>
<p align="center">This free script provided by<br />
<a href="http://javascriptkit.com"><b
style="color:black;background-color:#a0ffff">JavaScript</b>
Kit</a></p>
<p align="center">And adapted by <br />
<a href="http://www.engelsss.dyndns.org"><b
style="color:black;background-color:#a0ffff">Augusto</b>
Vyhmeister</a></p>
</body>
</html>
| Is This Answer Correct ? | 20 Yes | 11 No |
Answer / rubin thomas
u cant add a combo box dynamically u can add option
dynamically. Also if u want to show a combo box which is
hidden u can do that using showhide() function in js to show
or hide this element. but the box must be present in your code
.
| Is This Answer Correct ? | 21 Yes | 24 No |
Can any one tell me how Java is purely an Oops language
what is the source code for sendRedirect method()java Servlet program?
why is java platform indipedence
Write a way by which you can do something on the close of the window ?
How do you check if an object is an array or not?
How to add/remove properties to object dynamically in javascript?
What is the potential disadvantage of using a sticky session?
where we use javascript and for which purpose we use javascript how?
13 Answers Bugatti, IBM, Infosys, TCS,
What is output of “20” + 20 + 20 and “20” + ( 20 + 20)? In javascript?
What are the ways to define a variable in javascript?
how can count show data in grid view using java script
Which javascript is best?