Using javascript, I want generate buttons and textboxes dynamically depending on selection from dropdown.
Use asp.net with c# languasge.
I will try using above code.But not solved the purpose.Please suggest.
<head runat="server">
<title>Dynamically add Text Box and Button</title>
<script language="javascript" type="text/javascript">
function add(type)
{
for(i=0;i<10;i++)
{
var element=document.createElement("input");
element.setAttribute("type", type);
element.setAttribute("value", type);
element.setAttribute("name", type);
var foo=document.getElementById("fooBar");
foo.appendChild(element ,"<\br>");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>Dynamically add element in form </h2>
Select the element and hit Add to add it in form.
<br />
<select name="element">
<option value="button">Button</option>
<option value=" ">TextBox</option>
</select>
<input type="button" value="Add" onclick="add(document.forms[0].element.value)"/>
<br />
<span id="fooBar"></span>
<div>
</div>
</form>
</body>