How to add a combo box dynamically at run time in Java
script?

Answers were Sorted based on User's Feedback



How to add a combo box dynamically at run time in Java script?..

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

How to add a combo box dynamically at run time in Java script?..

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

How to add a combo box dynamically at run time in Java script?..

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

How to add a combo box dynamically at run time in Java script?..

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

How to add a combo box dynamically at run time in Java script?..

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

Post New Answer

More JavaScript Interview Questions

Is JavaScript a case-sensitive language?

0 Answers  


What is the use of a weakset object in javascript?

0 Answers  


What is this keyword?

9 Answers   Cognizant, Infosys, Satyam,


do any browser need activeX object to run javascripts?

2 Answers  


How you will add function as a property in a javascript object? Give an example.

0 Answers  






What is the purpose of using javascript?

0 Answers  


How do I get javascript?

0 Answers  


How can an HTMLCollection be traversed?

0 Answers  


Who created npm?

0 Answers  


What is a null variable in javascript?

0 Answers  


How can a particular frame be targeted, from a hyperlink, in javascript?

0 Answers  


What is difference between deep and shallow object coping in javascript?

0 Answers  


Categories