[HTML]<html>
<head>
<script language="javascript">
function createTable(id,ctr)
{
var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
var i;
for(i=1;i<=ctr;i++)
{
var row1td1=document.createElement('TD');
var row1td1sel=document.createElement('select' );
row1td1sel.setAttribute('id','PA'+i,'NAME','prefer ence_access');
row1td1.appendChild(row1td1sel);
var subrow1_y=document.createElement('option');
subrow1_y.innerHTML='Y';
subrow1_y.value=1;
var subrow1_n=document.createElement('option');
subrow1_n.innerHTML='N';
subrow1_n.value=2;
row1td1sel.appendChild(subrow1_y);
row1td1sel.appendChild(subrow1_n);
var row1td2=document.createElement('TD');
var row1td2sel=document.createElement('select' );
row1td2sel.setAttribute('id','RA'+i,'NAME','reques t_access');
row1td2.appendChild(row1td2sel);
var subrow2_y=document.createElement('option');
subrow2_y.innerHTML='Y';
subrow2_y.value=1;
var subrow2_n=document.createElement('option');
subrow2_n.innerHTML='N';
subrow2_n.value=2;
row1td2sel.appendChild(subrow2_y);
row1td2sel.appendChild(subrow2_n);
var row1=document.createElement('TR');
var row1td3=document.createElement('TD');
var row1td3_n=document.createElement('INPUT');
row1td3.appendChild(row1td3_n);
row1td3_n.setAttribute('TYPE','text');
row1td3_n.setAttribute('NAME','UID'+i);
row1td3_n.setAttribute('ID','UID'+i);
var row1td4=document.createElement('TD');
var row1td4_n=document.createElement('INPUT');
row1td4.appendChild(row1td4_n);
row1td4_n.setAttribute('TYPE','text');
row1td4_n.setAttribute('NAME','CID'+i);
row1td4_n.setAttribute('ID','CID'+i);
row1.appendChild(row1td1);
row1.appendChild(row1td2);
row1.appendChild(row1td3);
row1.appendChild(row1td4);
tbody.appendChild(row1);
}
}
function addRowToTable()
{
var tbl = document.getElementById('t1head');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// select cell
var cell1 = row.insertCell(0);
var sel1 = document.createElement('select');
sel1.name = 'Categories';
sel1.id='RA'+iteration;
sel1.options[0] = new Option('Y', '0');
sel1.options[1] = new Option('N', '1');
cell1.appendChild(sel1);
// select cell
var cell2 = row.insertCell(1);
var sel2 = document.createElement('select');
sel2.name = 'preferences_access';
sel2.id='PA'+iteration;
sel2.options[0] = new Option('Y', '0');
sel2.options[1] = new Option('N', '1');
cell2.appendChild(sel2);
// left cell
var cell3 = row.insertCell(2);
var textNode = document.createElement('input');
textNode.setAttribute('type','text','name','text'+ iteration,'id','txt'+iteration);
cell3.appendChild(textNode);
// right cell
var cell4 = row.insertCell(3);
var el = document.createElement('input');
el.type = 'text';
el.name = 'text' + (iteration+1);
el.id = 'txt' + (iteration+1);
cell4.appendChild(el);
}
</script>
<body bgcolor="#fffcd0" onLoad=createTable('t1head',0)>
<form >
<table class="layout" border="4" align="center" width="100%" id=t1head>
<tr>
<td align="left"><b> Categories </b></td>
<td align="left"><b> Items </b></td>
<td align="left"><b> Quantity </b></td>
<td align="left"><b> Price </b></td>
</tr>
</table>
<table>
<tr><td></td></tr><tr><td></td></tr>
<tr><td></td></tr></tr><tr><td></td></tr>
</tr><tr><td></td></tr><tr><td></td></tr>
<tr><td></td></tr></tr><tr><td></td></tr>
</table>
<table class="layout" border="0" align="center" id=tabBtn>
<tr>
<td align="center" colspan="2">
<input type="button" value="ADD" name="add" onClick="addRowToTable()">
</td>
<td align="center" colspan="2">
<input type="submit" value="SAVE" name="save">
</td>
<td align="center" colspan="2">
<input type="button" value="CANCEL" name="cancel" onClick="history.go(0)">
</td>
</tr>
</table>
</form>
</body>
</html>
[/HTML]
The above code is taken from the same forum posted by u which is the required one for me..Now my problem is the two dropdown boxes in which i have used ajax..i cant incorporate it in ur above code...the code which i tried was:
- function generateRow() {
-
var d=document.getElementById("div");
-
d.innerHTML+="Category : ";
-
-
d.innerHTML+="<select name='Categories' id='Categories" + numLinesAdded + "' onChange='itemCollect(this.value," + numLinesAdded + ")'><option value=''>------Select Category------</option><?php while($resultset=mysql_fetch_array($category)){?><option value='<?=$resultset['category_id'];?>'><?=$resultset['Categories']; ?></option><?php }?></select> ";
-
-
d.innerHTML+="Items : ";
-
-
d.innerHTML+="<select id='itemList" + numLinesAdded + "'><option value=''>------Select an Item------</option></select> ";
-
-
d.innerHTML+="Quantity : ";
-
-
d.innerHTML+="<input type='text' maxlength='5' name='Quantity" + numLinesAdded + "' onkeypress='focusNext(this)'> ";
-
-
d.innerHTML+="Price : ";
-
-
d.innerHTML+="<input type='text' name='Price" + numLinesAdded + "'><br><br>" ;
-
numLinesAdded++;
-
}
-
The values for the dropdown are taken directly from the database through ajax...Is it possible to fulfill my requirement????pls help me...
The problem with my code is that whenever i click "submit",the values in the dropdown gets refreshed and not saved which is rectified in ur code..