472,364 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 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 17357
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:-
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.