473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to generate new row on each row button click

i want to generate a new row having text field,1 add button and 1 remove button..each time when we press add button of current row same way a new row should be generated with same functinality of its add button..
similarly same should happen with remove button that is when we click on remove button the same row should be deleted of which remove button is pressed..
Sep 2 '08 #1
9 17691
Dormilich
8,658 Expert Mod 8TB
Usually I would do that in JavaScript. Nevertheless it's possible in PHP too. I'm looking forward to your code, so we can discuss problems (if there are any).

kind regards
Sep 2 '08 #2
Usually I would do that in JavaScript. Nevertheless it's possible in PHP too. I'm looking forward to your code, so we can discuss problems (if there are any).

kind regards


dear sir i am novice in php .
I need this done in php exclusively.
As u were asking i am sending my code to u below:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>
  4. </title>
  5. </head>
  6. <body>
  7. <form name="form1" method="POST" action="">
  8. <table>
  9.  <tr>
  10. <td><input type="text" name="txt" align="center"> </td>
  11. <td><input type="submit" name="btnadd" id="btnadd" value="ADD"> </td>
  12. <td><input type="submit" name="btnremove" id="btnremove" value="REMOVE"> </td>
  13. <td><input type="hidden" name="hidden"  value="abc<?PHP ($j)?>"> </td>
  14. </tr></table>
  15.  
  16. <?PHP
  17.  if($_POST["btnadd"] == "ADD")
  18. {
  19. $j=0;
  20. for($i=0;$i<$j+1;$i++)
  21. {
  22.  ?>
  23. <table>
  24. <tr>
  25. <td><input type="text" name="txt" align="center"> </td>
  26. <td><input type="submit" name="btnadd" id="btnadd" value="ADD"> </td>
  27. <td><input type="submit" name="btnremove" id="btnremove" value="REMOVE"> </td>
  28. <td><input type="hidden" name="hidden"  value="$j ;"> </td>
  29. </tr>
  30. </table>
  31. <?PHP 
  32. }
  33. }
  34. ?>
  35.  
  36. </form>
  37.  
  38. </body>
  39. </html>
  40.  
Sep 2 '08 #3
Dormilich
8,658 Expert Mod 8TB
It looks (please correct me if I'm wrong) as if you want an additional input field added on pressing the 'ADD' button. and you don't want to retain the input (a page reload usually clears all fields).

a simplified version of your code could look like this
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title></title>
  4.     <style type="text/css">
  5. input {
  6.   display: block;   /* makes one <input> per line */
  7. }
  8.     </style>
  9.   </head>
  10. <?php
  11. if($_POST["btnadd"] == "ADD") {
  12. // add 1 to the row counter
  13.     if (isset($_POST['count'])) $count = $_POST['count'] + 1;
  14. // set value for first load
  15.     else $count = 1;
  16. }
  17. if($_POST["btnremove"] == "REMOVE") {
  18. // decrement the row counter
  19.     $count = $_POST['count'] - 1;
  20. // set minimum row number
  21.     if ($count < 1) $count = 1;
  22. }
  23. ?>
  24.   <body>
  25. <!-- call same file on submit -->
  26.     <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  27.  <?php 
  28. // print $count rows
  29. for ($i=1; $i<=$count; $i++) {
  30. echo '      <input type="text" name="txt" align="center">';
  31. }
  32. ?>
  33.  <!-- you only need one set of buttons and only one counter for this script
  34.       because every button would do the same -->
  35.       <input type="submit" name="btnadd" id="btnadd" value="ADD">
  36.       <input type="submit" name="btnremove" id="btnremove" value="REMOVE">
  37.       <input type="hidden" name="count" value="<?php echo $count; ?>">
  38.     </form>
  39.   </body>
  40. </html>
regards

PS: please use [code] tags when posting code
Sep 2 '08 #4
thnk u sir for ur help..ur coding is helped me to solve my problex..
thx
Sep 4 '08 #5
Dormilich
8,658 Expert Mod 8TB
I'm glad that I could help you.

kind regards
Sep 4 '08 #6
[
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title></title>
  4.     <style type="text/css">
  5. input {
  6.   display: block;   /* makes one <input> per line */
  7. }
  8.     </style>
  9.   </head>
  10. <?php
  11. if($_POST["btnadd"] == "ADD") {
  12. // add 1 to the row counter
  13.     if (isset($_POST['count'])) $count = $_POST['count'] + 1;
  14. // set value for first load
  15.     else $count = 1;
  16. }
  17. if($_POST["btnremove"] == "REMOVE") {
  18. // decrement the row counter
  19.     $count = $_POST['count'] - 1;
  20. // set minimum row number
  21.     if ($count < 1) $count = 1;
  22. }
  23. ?>
  24.   <body>
  25. <!-- call same file on submit -->
  26.     <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  27.  <?php 
  28. // print $count rows
  29. for ($i=1; $i<=$count; $i++) {
  30. echo '      <input type="text" name="txt" align="center">';
  31. }
  32. ?>
  33.  <!-- you only need one set of buttons and only one counter for this script
  34.       because every button would do the same -->
  35.       <input type="submit" name="btnadd" id="btnadd" value="ADD">
  36.       <input type="submit" name="btnremove" id="btnremove" value="REMOVE">
  37.       <input type="hidden" name="count" value="<?php echo $count; ?>">
  38.     </form>
  39.   </body>
  40. </html>
sir the coding u send me is exactly matches to suituation i want but but i want that particular row deleted up which row's remove button is clickd.and i want this all thing exclusively in php..plz hepl me sir ..

Thnk you.......
Sep 6 '08 #7
Dormilich
8,658 Expert Mod 8TB
does the input fields contain any data? if not it doesn't matter. In the other case you have to retain the data anyhow (maybe something like <input name="line[]">). then you have to apply somehow a line number to the button to tell which values to drop. I have to think about this problem (this wouldn't be a problem in JS). still you need only one add-button.
Sep 6 '08 #8
sir i only need this in php..to drop particular row whose remove button is being clicked
Sep 8 '08 #9
Dormilich
8,658 Expert Mod 8TB
general idea: name every submit button uniquely and check, which row this button belongs to.
[PHP]// get the 'number' of the pressed button
foreach (array_keys($_POST) as $key) {
if (preg_match('@^submit([0-9]+)$@', $key, $match) == 1) {
$no = $match[1];
$count--;
}
}

// remove value
unset($_POST['text'][$no]);
// re-index array
$retain = array_values($_POST['text']);

for ($i=0; $i<$count; $i++) {
echo ' <input type="text" name="text[]" value="' . $retain[$i] . '" />
<input type="submit" name="submit' . $i . '" value="remove" />
<br />';
}
[/PHP]
Sep 8 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Laphan | last post by:
Hi Guys I need logical help The best way that I can explain what I want is if you could do the following: 1) Go to http://www.fixturelist.com/createalist.php 2) Name doesn't matter put...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
0
by: Avon | last post by:
Hi friends, I am very sorry for my not perfect English. I have one question, I am using David Bauer's DynamicControlsPlaceholder to dinamically generate controls and I am tryig to generate...
6
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
15
by: Orchid | last post by:
Hello, I am looking to generate a unique ID field on MS. Access. The ID is with 10 digits with the combination of 5 Letters from the 26 letters and 5 Numbers from 1 to 9. The letters and numbers...
3
by: perhapscwk | last post by:
2 frame....i want to make it when i click the button fom left frame, it will generate a option box in right frame. By click different button in left frame, the option box generate from right...
8
by: sejal17 | last post by:
hello everyone, I have a problem with dynamically generating textbox.I have one link button .i want that when i click on link button then text box is created.when i click next time it...
5
by: ravindarjobs | last post by:
Hi friends, i am using ajax in asp.net. i am using tab container, tab panel controls. i want to add tab panel control dynamically on button click. i form code is:
1
by: vineet1987 | last post by:
i want to generate a series of random numbers like 00101 01011 01111 01010 11101 it is a 5*5 matrix and is random every time upon execution my code is:-
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.