Hi All,
I have a form with a button. On clicking the button, i need to dynamically add a list to the form and then add items to that list. I was able to add a list dynamically. But i am not able to add items to that list. I have seen many examples where the list already exists in the form, and we can dynamically add items to that list(with help of ‘document.form.list_name.options.add(new Option(‘the item’)) . But in my case, the list itself is dynamically created. So i am confused on adding items dynamically.
I tried calling two functions in the button click. In the first function the list will be added and in the second function the items get added. But this does not work.
Here is my code:
[CODE]<html>
<head>
<script language = “javascript”>
function selectItems()
{
var select_type = document.createElement(‘select’);
var type = document.createAttribute(‘name’);
var id = document.createAttribute(‘id’); select_type.setAttribute(type,’related_items’); select_type.setAttribute(id,’related_items’);
document.body.insertBefore(select_type);
}
function dynamicItems()
{
document.ss.related_items.options.add(new Option(‘Chennai’); //related_items is the id of the list which i dynamically created
}
<body>
<form name=’ss’>
<input type=”button” value=”click” onClick=”selectItems(),dynamicItems()”> //called two functions
</form>
</body>
</html>
Can anyone please help me on this?