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 the difference between window & document in javascript?
What is a global variable in programming?
How to achieve inheritance in javascript?
How to call a function in every x seconds in javascript?
Explain the difference between javascript and an asp script.
Why is currying called currying?
Is javascript object a hash table?
In a pop-up browser window, how do you refer to the main browser window that opened it?
How to detect the operating system on the client machine?
How to reload the current page?
What's the purpose of javascript?
What are the seven data types of javascript?
How to remove the event listener?
Is javascript enabled on my computer?
Difference between window.onload and onDocumentReady?