4 Replies - 719 Views - Last Post: 30 August 2013 - 03:46 AM

#1 Gkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 13

How To Add Values From Dynamically Added Rows Into Database

Posted 29 August 2013 - 02:54 AM

<html> 
<head> 
<script> 
function clonetable() 
{ 
var x=document.getElementById("main_table"); //get the table 
var rowCount = x.rows.length; 
var row = document.getElementById("table_row_clone"); // find row to copy
var table = document.getElementById("table_body"); // find table to append to 
var clone = row.cloneNode(true); // copy children too 
//var tb = document.getElementById("asn");
//var rowCount = x.rows.length; 
//var y=document.getElementById("maintable");
//var count=y.rows.length;
var tb1 = clone.document.getElementById("asn");
//tb1.value = parseInt(tb1.value, 10) + 1;
tb1.value=rowCount+1;
//tb1.value=count+1;

Page on Clone = "abc"; // change id or other attributes/contents 
table.appendChild(clone); // add new row to end of table 


} 

function deltable() 
{ 
var x=document.getElementById("main_table"); //get the table 
var rowCount = x.rows.length; 

if(rowCount>1) 
{ 
x.deleteRow(rowCount-1); 
}//delete the last row 
} 


</script> 

</head> 
<body> 
<table id="main_table" align="center" style="width:75%" > 

<tbody id="table_body"> 
<tr id="table_row_clone"> 
<td> 
<table align="center" style="width:100%" > 

<tr > 
<td align="center"> 
<div style="border:3px solid silver;border-radius:5px;background-color:grey"> 
<table width="100%" > 
<tr> 
<th align="center" > 
Address Details 
</th> 
</tr> 
</table> 
</div> 
</td> 
</tr> 

<tr> 
<td> 
<div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> 
<table align="center" style="width:99%"> 
<tr style="background-color:#1E90FF"> 

<td style="width:35%"> 
<table width="100%"> 
<tr id="slrow"> 
<td style="width:43%"> 
Address Seq Num 
</td> 
<td> 
<input id="asn"style="width:60px" name="address_seq_num" type="text" value="1" readonly> 
</td> 
</tr> 
</table> 
</td> 

<td width="49%" align="right" > 
<input style="width:80%" type="text" value="Reg.office/Primary Office"> 
</td> 

<td align="right"> 
<input style="width:30px" type="button" value="+" onclick="clonetable()"> 
<input style="width:30px" type="button" value="-" onclick="deltable()"> 
</td> 
</tr> 
</table> 
</div> 
</td> 
</tr> 

<tr> 
<td> 
<div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> 
<table align="center" style="width:99%" > 
<tr > 

<td align="left" style="width:50%"> 
<table width="100%"> 
<tr> 
<td style="width:30%"> 
Effective Date 
</td> 
<td style="width:70%" > 
<input style="background-color:white;width:44.5%" name="effdt" type="text" class="tcal"> 
</td> 
</tr> 
</table> 
<td style="width:50%"> 
<table width="100%" > 
<tr> 
<td align="right"> 
Effective Status 
</td> 
<td style="width:45%"> 
<select name="eff_status" name="eff_status" style="float:right;width:145px" id="estatus"> 

<option value="Active" selected>Active</option> 
</select> 
</td> 
</tr> 
</table> 
</td> 
</tr> 
</table> 
</div> 
</td> 
</tr> 

</table> 
</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>


1)here i'm doing clone of a row...but this code is working only in eclipse [ ie ,cloning is working ] and it is also not working in anybrowsers.
if i write
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "Page on W3">
to this code ,it will not work in eclipse also.....

[img]C:\Users\Gopalkrishna\Desktop\Capture.PNG[/img]


first image is showing cloning of rows

1)first address seq number wiil be 1, and user will enter effective date and effective status...

2)when user click [+] the next row will comes with auto increment of address seq num=2... and user will enter rest of the fields...

3)my problem is...how can i insert the subsequent "address seq number" , "effective date" and "effective status" to subsequent rows in the database table as i shown in the below image....
cosider this image as a table in database
C:\Users\Gopalkrishna\Desktop\Capture1.PNG
bt the values on the dynamically added rows are not being saved into the datase. only the values of the first row is being added.

please guide me...Attached Image
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: How To Add Values From Dynamically Added Rows Into Database

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: How To Add Values From Dynamically Added Rows Into Database

Posted 29 August 2013 - 07:41 AM

line 15, document is not a property of clone (unless clone is a reference to window, but here it is a table row)

line #20, not valid JS code.

This post has been edited by Dormilich: 29 August 2013 - 07:43 AM

Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: How To Add Values From Dynamically Added Rows Into Database

Posted 29 August 2013 - 07:50 AM

the table code indented for better readability:
<table align="center" style="width:100%" > 
	<tr > 
		<td align="center"> 
			<div style="border:3px solid silver;border-radius:5px;background-color:grey"> 
			
				<table width="100%" > 
					<tr> 
						<th align="center" > Address Details </th> 
					</tr> 
				</table> 
				
			</div> 
		</td> 
	</tr> 
	<tr> 
		<td> 
			<div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> 
			
				<table align="center" style="width:99%"> 
					<tr style="background-color:#1E90FF"> 
						<td style="width:35%"> 
						
							<table width="100%"> 
								<tr id="slrow"> 
									<td style="width:43%"> Address Seq Num </td> 
									<td> 
										<input id="asn"style="width:60px" name="address_seq_num" type="text" value="1" readonly> 
									</td> 
								</tr> 
							</table> 
							
						</td> 
						<td width="49%" align="right" > 
							<input style="width:80%" type="text" value="Reg.office/Primary Office"> 
						</td> 
						<td align="right"> 
							<input style="width:30px" type="button" value="+" onclick="clonetable()"> 
							<input style="width:30px" type="button" value="-" onclick="deltable()"> 
						</td> 
					</tr> 
				</table> 
			
			</div> 
		</td> 
	</tr> 
	<tr> 
		<td> 
			<div style="border:3px solid silver;border-radius:5px;background-color:#1E90FF"> 
			
				<table align="center" style="width:99%" > 
					<tr > 
						<td align="left" style="width:50%"> 
						
							<table width="100%"> 
								<tr> 
									<td style="width:30%"> Effective Date </td> 
									<td style="width:70%" > 
										<input style="background-color:white;width:44.5%" name="effdt" type="text" class="tcal"> 
									</td> 
								</tr> 
							</table> 
							
						<td style="width:50%"> 
						
							<table width="100%" > 
								<tr> 
									<td align="right"> Effective Status </td> 
									<td style="width:45%"> 
										<select name="eff_status" name="eff_status" style="float:right;width:145px" id="estatus"> 
											<option value="Active" selected>Active</option> 
										</select> 
									</td> 
								</tr> 
							</table> 
							
						</td> 
					</tr> 
				</table> 
			
			</div> 
		</td> 
	</tr> 
</table> 

omg!
Was This Post Helpful? 0
  • +
  • -

#4 Gkp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-August 13

Re: How To Add Values From Dynamically Added Rows Into Database

Posted 30 August 2013 - 01:08 AM

View PostDormilich, on 29 August 2013 - 07:41 AM, said:

line 15, document is not a property of clone (unless clone is a reference to window, but here it is a table row)

line #20, not valid JS code.



thanks for the reply...
what i have to use instead of line 15 to change the value of "asn"...please tell me...

is there any other way to add this big row other than clone method....
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: How To Add Values From Dynamically Added Rows Into Database

Posted 30 August 2013 - 03:46 AM

View PostGkp, on 30 August 2013 - 10:08 AM, said:

what i have to use instead of line 15 to change the value of "asn"...please tell me...

delete clone.

View PostGkp, on 30 August 2013 - 10:08 AM, said:

is there any other way to add this big row other than clone method....

I’d strongly advise to not use nested tables to begin with. (makes it much easier later)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1