Add fields dynamically

[nobr]Hi all,

When add button is clicked then textboxes and drop down boxes appears ..

<html>

<head>

<body onload="fillproduct();">

<script language="javascript" src="list.js"></script>

<script>

function generateRow(){

var d=document.getElementById("div");

d.innerHTML+="<select name='product' onChange='Selectprod_method();' ><option value=''>-select product-</option></select><select id='prod_method' name='prod_method' ><option selected value=''><--</option></select>";

d.innerHTML+="<input type='text' name='txt1_' onkeypress='focusNext(this)'>";

d.innerHTML+="<input type='text' name='txt2_ '><br>" ;

}

</script>

</head>

<form name="drop_list">

<div id="div"></div>

<select name='product' onChange='Selectprod_method();' ><option value=''>-select product-</option></select>

<select id='prod_method' name='prod_method' ><option selected value=''><--</option></select>

<input type="button" value="Add" onclick="generateRow()"/>

<input type="submit">

</form>

</body>

</html>

Here the drop down box which existsdefault loads [b]fillproduct()[/b] function but the drop down called from innerHTML not loading that function.

I stuck here.

Can anyone help me out.

[/nobr]

[2062 byte] By [a1ba] at [2007-11-27 10:22:18]
# 1

The element.innerHtml just represents plain HTML, not the actual elements.

Use document.createElement() to create elements and element.appendChild() to append child elements to the parent element.

BalusCa at 2007-7-28 17:15:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

[nobr]But still dynamic drop down is not working ....

<HTML>

<HEAD>

<script language="javascript" src="list.js"></script>

</HEAD>

<FORM name='drop_list' action='' method='POST'>

<SCRIPT>

function list(){

var newRadioButton = document.createElement("<select name='product' onChange='Selectprod_method();' ><option value=''>-select product-</option></select>")

document.body.insertBefore(newRadioButton);

var newRadioButton = document.createElement("<select id='prod_method' name='prod_method' onChange='Selectprod_sys();' ><option selected value=''><--</option></select>")

document.body.insertBefore(newRadioButton);

var newRadioButton = document.createElement("<select id='prod_sys' NAME='prod_sys'><option selected value=''><--</option></select>")

document.body.insertBefore(newRadioButton);

}

</SCRIPT>

<BODY onload='fillproduct();'>

<select name='product' onChange='Selectprod_method();' ><option value=''>-select product-</option></select><select id='prod_method' name='prod_method' onChange='Selectprod_sys();' ><option selected value=''><--</option></select><select id='prod_sys' NAME='prod_sys'><option selected value=''><--</option></select>

<INPUT TYPE="BUTTON" ONCLICK="list()" VALUE="ADD"><BR>

<INPUT TYPE="BUTTON" ONCLICK="alert ( document.body.outerHTML )" VALUE="Click here to see HTML">

</BODY>

</HTML>

Pls help me to correct this.[/nobr]

a1ba at 2007-7-28 17:15:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Any help?

a1ba at 2007-7-28 17:15:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...