Jump to content

Add values in a dynamic table (php/javascript)


pb1uk

Recommended Posts

Hello all,

 

My problem is php/javascript, so i didn't know which board to post on! I have a table to update all records in a table in a database. The table displays fine and updates ok. However what i'm trying to do is add two values together in order to obtain the value to be input into the database.

 

At the moment my code is:

 

<form name="addgkscores" method="post" action="" >
<table border="1">
 <tr>
 <td>id</td>
   <td>gkname_gk</td>
  <td>PLD</td>
  <td>CLN</td>
   <td>points</td>

 </tr>
 <?php while($row_rs_test=mysql_fetch_array($rs_test)) { ?>
   <tr>
   <td><?php echo $row_rs_test['gkid_gk']; ?></td>
     <td><?php echo $row_rs_test['gkname_gk']; ?></td>
     <td><input type="text" id="p" size="3" value="0" /></td>
     <td><input type="text" id="c" size="3" value="0" /></td>
     <td><input name="foo[<?php echo $row_rs_test['gkid_gk']; ?>]" type="text" id="test" value="<?php echo $row_rs_test["$scoreweek"]; ?>" /></td>

   </tr>

   <?php } ?>
</table>
<input type="hidden" name="week" value="<?php echo $scoreweek; ?>">
<input type="button" name="addbutton" onclick="calculatescores(p.value, c.value)" value="add"/>
<input type="submit" value="Insert scores" name="submit"/>

</form>

 

This is what i have upto now. I need to add the value of p to the value of c and return this value in the column id="test". I haven't included my javascript function as it doesn't work! I can get two fields to add up and return it in a blank field but because this is a dynamic table there are around 30 records in this table to update and i'm not sure how to do this for each one.

 

I've searched around for a solution but have been unable to find anything. Any help would be brilliant.

 

Thanks,

 

pb1uk

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...