Jump to content

Retain dynamically added rows on click of Back


karthikjayraj

Recommended Posts

Hi,

 

I have set up 2 php pages

 

page 1 - add_entry2.php

In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php

In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1

 

Now the problem starts here

on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it.

 

One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. 

 

here is the code(I have removed the java script functionalities to reduce length of the post)

 

add_entry2.php

<html>
     <head>
          <title>Page Title</title>
     </head>
     <body leftmargin="0" topmargin="0">

          <!--- forms are good when you wanna actually do stuff --->
          <form action="add_entry3.php" name="eval_edit" method="post" format="html">
               <table align="center" width = "75%">
                    <tr>
                         <td align = "center">
                              Invoice
                         </td>
                    </tr>
                    <tr>
                         <td align = "center">
                              <!--- very imporant to give the table an id --->
                              <!--- otherwise it won't know where to edit --->
                              <table border="1" id="mySampleTable">
                                     <tr>
								 	<th>Item No</th>
									<th>Item Name</th>
									<th>Item code</th>
									<th>Description</th>
									<th>Unit Cost</th>
									<th>Quantity</th>
									<th>Price</th>
									<th>Cancel ?</th>
                                   </tr>
								<tr>
									<td>1</td>
									<td><input type="text" name="itemname[]"  size="40" maxsize="100"/></td>
									<td><input type="text" name="itemcode[]" size="20" maxsize="100" /></td>
									<td><input type="text" name="description[]" size="20" maxsize="100" /></td>
									<td><input type="text" name="unitcost[]" size="10" maxsize="100" /></td>
									<td><input type="text" name="quantity[]" size="4" maxsize="100" /></td>
									<td><input type="text" name="price[]" size="10" maxsize="100" /></td>
									<td><input type="CHECKBOX" name="cancel[]"/></td>
							   </tr>
						  </table>
							<table id="totaltbl">
							  <tr>
								<th>Total</th>
								<th>Vat%</th>
							  </tr>
							  <tr>
								<td><input type="text" name="total" size="20" maxsize="100" /></td>
								<td><input type="text" name="total" size="3" maxsize="3" /></td>
							  </tr>
							</table>

                              <!--- our buttons call our javascript functions when clicked --->
				<p>	
					<input type="button" value="Add Row" onclick="addRow();" />	
					<input type="button" value="Calculate Total Amount" onclick="Totalcal();" />	
					<input type="hidden" name="count" value=""/>
					<!--<input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />-->
					<input type="submit" name="submit" value="View Bill" />
					<input type="hidden" name="submitted" value="true" />

				</p>

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

 

****************************************************8888

This is

add_entry3.php

 
<?php 

	$num=count($_POST['itemcode']);		
	$itemname= $_POST['itemname'];
	$itemcode = $_POST['itemcode'];
	$unitcost = $_POST['unitcost'];
	$description = $_POST['description'];
	$unitcost = $_POST['unitcost'];
	$quantity = $_POST['quantity'];
	$price = $_POST['price'];
	$problem = FALSE;
	?>
	<h1 align ="center"><b><u>Invoice Details</b></u></h1>
	               <table align="center" width = "75%">
                    <tr>
                         <td align = "center">
  <table border="1" id="mySampleTableheader">
	 <tr>
		<td width="75"><b>Item No</b></td>
		<td width="275"><b>Item Name</b></td>
		<td width="155"><b>Item code</b></td>
		<td width="155"><b>Description</b></td>
		<td width="95"><b>Unit Cost</b></td>
		<td width="60"><b>Quantity</b></td>
		<td width="95"><b>Price</b></td>
   </tr>
  </table>
	<?php
	$i=0;
	while ($i < $num) {
	?>
	<!--- forms are good when you wanna actually do stuff --->
          <form action="save_entry.php" name="eval_edit" method="post" format="html">

<table  border="1"  id="mySampleTable">
<tr>
<td width="75"><?php echo $i+1; ?></td>
<td><input type="text" name="itemname[]"  value = "" size="40" maxsize="100" readonly/></td>
<td><input type="text" name="itemcode[]" value ="<?php echo $itemcode[$i]; ?>" size="20" maxsize="100" readonly/></td>
<td><input type="text" name="description[]" value ="<?php echo $description[$i]; ?>" size="20" maxsize="100" readonly/></td>
<td><input type="text" name="unitcost[]" value ="<?php echo $unitcost[$i]; ?>" size="10" maxsize="100" readonly/></td>
<td><input type="text" name="quantity[]" value = "<?php echo $quantity[$i]; ?>" size="4" maxsize="100" readonly/></td>
<td><input type="text" name="price[]" value =  "<?php echo $price[$i]; ?>" size="10" maxsize="100" readonly/></td>
</tr>
</table>

<?php
	$i++;}
?>


                              <!--- our buttons call our javascript functions when clicked --->
				</td>
				</tr>
				</table>
				<p>	
						<table id="totaltbl">
							  <tr>
								<th>Total</th>
							  </tr>
							  <tr>
								<td><input type="text" name="total" size="20" maxsize="100" /></td>
							  </tr>
							</table>
					<input type="button" value="Add Row" onclick="addRow();" />	
					<input type="button" value="Row count" onclick="countRow();" />	
					<input type="hidden" name="count" value=""/>
					<!--<input type="hidden" name="count" value=""/>
					<input type="submit" name="submit" onclick="countRow();" value="Insert into Invoice!" />-->
					<input type="button" value="Back" onClick="history.go(-1);return true;">
					<input type="submit" name="submit" value="Finalise" />
					<input type="hidden" name="submitted" value="true" />
				</p>

          </form>

     </body>
</html>

I am able to retain values if I use i,e if I submit back to the same page and retrieve values form $_POST

 

<form action="add_entry2.php" name="eval_edit" method="post" format="html">

 

but If I use the code below to get back to add_entry2.ph it looses all the values. Is there any other way to code the back page retaining my $_POST values

 

<input type="button" value="Back" onClick="history.go(-1);return true;">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.