473,406 Members | 2,954 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,406 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 17746
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.