How to append Row with values in it using ajax

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ullasvk
Forum Newbie
Posts: 21
Joined: Fri Feb 13, 2009 11:55 pm

How to append Row with values in it using ajax

Post by ullasvk »

Hello Friends,
Almost i have written code for adding a row which contain many "<select>" menu which takes value from database. But the problem is, every time i click add row it adds a row but changes the values that i have changed previously in "<select>" menu to default values i.e it erases the values i have entered and add a new row with default values. What i want is to append a row with keeping the changed values as it is. Here is the code i have written..

Please any one help me..

Code: Select all

 [/b]

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html><head><title>New Order</title>
<meta http-equiv=content-type content="text/html; charset=utf-8">
<link href="style.css" type=text/css rel=stylesheet>
<meta content="mshtml 6.00.2900.2180" name=generator>
<script language="JavaScript" type="text/JavaScript">
var new_row;
function read()
{
 new_row = document.getElementById("add").innerHTML;
}
function ajaxFunction()
{
document.getElementById("add").innerHTML = document.getElementById("add").innerHTML+new_row;
}
</script>
</head>
<body onLoad="read();">
<?php include ("includes/connection.php"); ?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center">
	<table width="780" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
<table width="780" bgcolor="#ffffff" border="0">
  <tr>
    <td><img src="images/top1.JPG" width="780" height="202" /></td>
  </tr>
  <tr>
    <td><b><center>New Order</center></b></td>
  </tr>
  <tr>
    <td><table width="780"   border="0">
  <tr>
      <td>
     <form name="form" action="order1.php" method="POST" >

<table width="640" height="28" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#C6C6C6">
  <tr>
      [b]<td width="80"><input name="Add_row" type="button" value="Add_row" onClick="ajaxFunction()"></td>[/b]
  </tr>
</table>
<div id="add"> 
<table width="640" border="1" align="center" cellpadding="0" cellspacing="0">
  <tr>
       <td width="63"><div align="center">
     <select name="density[]" id="density" >
     <?php
$query2 = "SELECT * FROM DENSITY";
$result2 = mysql_query($query2);
while ($line2 = mysql_fetch_array($result2)) {
?>
  <option value="<?php echo $line2["density"] ?>"><?php echo $line2["density"] ?></option>
      <?php
}
?>
     </select>
    </div></td>
    <td width="98"><div align="center">
     <select name="size[]" id="size">
       <?php
$query3 = "SELECT * FROM SIZE";
$result3 = mysql_query($query3);
while ($line3 = mysql_fetch_array($result3)) {
?>
  <option value="<?php echo $line3["si_len"] ?>"><?php echo $line3["si_len"] ?>x<?php echo $line3["si_bred"] ?></option>
      <?php
}
?>
     </select>
    </div></td>
   <td width="68"><div align="left">
     <select name="th_id[]" id="thick">
     <?php
$query4 = "SELECT * FROM THICK";
$result4 = mysql_query($query4);
while ($line4 = mysql_fetch_array($result4)) {
?>
  <option value="<?php echo $line4["th_id"] ?>"><?php echo $line4["thick"] ?></option>
      <?php
}
?>
     </select>
   </div></td>
    <td width="78"><div align="center">
     <input name="no_of_bun[]" type="text" size="5">
    </div></td>
   <td width="75"><div align="center">
     <select name="grade[]" id="grade">
       <?php
$query5 = "SELECT * FROM GRADE";
$result5 = mysql_query($query5);
while ($line5 = mysql_fetch_array($result5)) {
?>
  <option value="<?php echo $line5["grade"] ?>"><?php echo $line5["grade"] ?></option>
      <?php
}
?>
     </select>
    </div></td>

    <td width="81" style="border:#FFFFFF"></td>
  </tr>
</table>
</div>
<p align="center"><input name="submit" type="submit" value="Submit" ></p>
     </form>	 </td>
  </tr>
</table></td>
  </tr>
  <tr>
    <td><img src="images/bottom.jpg" width="780"></td>
  </tr>
</table>
</td>
 </tr>
	</table>
      	</td>
  </tr>
</table>
</body></html>


[b][/b]
Last edited by ullasvk on Tue Feb 17, 2009 2:32 am, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to append Row with values in it using ajax

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Post Reply