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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there automatic type conversion in JavaScript?

539


What are global variables? How are these variable declared and what are the problems associated with using them?

521


What is the difference between local storage & session storage?

470


What is the use of a weakset object in javascript?

539


How to get the last index of a string in javascript?

495






How to create a confirmation box?

535


What is unshift method in JavaScript?

552


what is the difference between the below two statements:- (1) var myname = "akiii"; (2) myname = "akiii";

533


What is event in javascript?

476


Is javascript whitespace sensitive?

487


Does spread operator deep copy?

538


What are the features of javascript?

482


How do I turn on javascript?

429


Do you have to declare variables in javascript?

487


What are 2 (shorthand) boolean operators supported by javascript

469