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
Submit Button Click
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Submit Button Click
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>";
}
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Submit Button Click
thank you for the reply.....
I cant get the value
echo $_POST["txtVal"];
is this the only in the other page?
I cant get the value
echo $_POST["txtVal"];
is this the only in the other page?
Re: Submit Button Click
One way to do this, is to give all of your submit buttons the same name: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>"; }
Code: Select all
echo '<input name="math" value="Add" type="Submit">';
echo '<input name="math" value="Subtract" type="Submit">';
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;
}Unless I'm misunderstanding the question, which I might be.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Submit Button Click
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
Multiple+submit+buttons+in+one+form
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering