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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain arrow functions?

567


Is a javascript script faster than an asp script?

558


Write a program to reverse a string in pure javascript?

572


What is question mark in javascript?

572


What is argument objects in javascript & how to get the type of arguments passed to a function?

582






how can we retrieve value from one database server and store them another database server using sql server code

1652


Is javascript necessary for web development?

621


What is enum data type?

564


What does => mean in node js?

635


How do I use javascript to password-protect my web site?

558


What is unobtrusive javascript? How to add behavior to an element using javascript?

598


what is the difference between let, var, and const?

644


What is screen object in JavaScript?

645


How do you write a comment in javascript?

521


What is the difference between innerhtml and append() in javascript?

752