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
What is event bubbling in JavaScript?
Who created npm?
How do you create array in javascript?
Write the code for adding new elements dynamically?
What is the use of a typedarray object in javascript?
What is the most widely used programming language?
What is the difference between innerHTML and innerText?
What is enum in javascript?
How to convert a string to a number using javascript?
Why javascript is so popular?
What output will this program produce System.out.println(x+"+"+y+"="+(x+));
How can you detect the client operating system using javascript?
What are the five data types?
What is a hash javascript?
What data types are supported in Javascript?