Page 1 of 1

Submit Button Click

Posted: Thu Mar 03, 2011 2:05 am
by ms.Jemi
Hi everyone!
I have a problem in submit button.
I have dynamic input fields and submit button.
Each input Fields has a submit button.

So, when I click the first button, I want to get the value of its corresponding input field.
Can you guys, help me out?...please...
Here is the sample code for generating input fields and submit buttons

<form name="form1" method="post" action="practice1.php">
<?php
for($x=0;$x<3;$x++){
echo '<input name="txtVal[]" type="text">';
echo '<input name="sub[]" value="Add" type="Submit">';
echo "<br>";
}

?>
Guys..please I really need ur ideas....Thank You

Re: Submit Button Click

Posted: Thu Mar 03, 2011 10:54 am
by social_experiment
You'd probably have to generate a complete form for each button. You can only have 1 submit button per form because you only have 1 action per form.

Code: Select all

<?php
for($x=0;$x<3;$x++){
echo '<form name="form ' . $x .'" method="post" action="practice1.php" >';
echo '<input name="txtVal[]" type="text">';
echo '<input name="sub[]" value="Add" type="Submit">';
echo '</form>
echo "<br>";
}
?>

Re: Submit Button Click

Posted: Thu Mar 03, 2011 12:34 pm
by ms.Jemi
thank you for the reply.....

I cant get the value
echo $_POST["txtVal"];
is this the only in the other page?

Re: Submit Button Click

Posted: Thu Mar 03, 2011 3:55 pm
by Iswald
ms.Jemi wrote:Hi everyone!

Code: Select all

<form name="form1" method="post" action="practice1.php">
<?php
for($x=0;$x<3;$x++){
echo '<input name="txtVal[]" type="text">';
echo '<input name="sub[]" value="Add" type="Submit">';
echo "<br>";
}
?>
One way to do this, is to give all of your submit buttons the same name:

Code: Select all

echo '<input name="math" value="Add" type="Submit">';
echo '<input name="math" value="Subtract" type="Submit">';
In your form processing code, do a switch based on the value of the submit button's name:

Code: Select all

switch ($_POST['math']) {
  case "Add":
   // do some adding
    break;
  case "Subtract":
   // do some subracting
    break;
  default:
  // whatever happens when things break
    break;
}
I'd thought I'd misplaced the link I got this idea from (needing to do the same thing), but here it is: http://www.techrepublic.com/article/han ... hp/5242116

Unless I'm misunderstanding the question, which I might be.

Re: Submit Button Click

Posted: Fri Mar 04, 2011 10:16 am
by social_experiment
My bad. I thought html conventions only allowed for 1 submit button per form. Here is another URL you can look at
Multiple+submit+buttons+in+one+form