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

How to get value from radiobuttonlist control?

502


What is a fixed-width table and its advantages?

497


Can we learn javascript without knowing java?

485


What would you use javascript for?

494


What creates scope in javascript?

492






What is called variable typing in javascript?

528


What is a hash javascript?

536


Is there any ide for javascript?

529


What is a currying function?

494


What does the following statement declares?

492


How typeof operator works?

576


What is the difference between innerHTML and innerText?

530


Can you use javascript to hack?

468


What does the enableviewstatemac setting in an aspx page do?

526


What are different types of inheritence? Which inheritance is followed in javascript.

441