I need to create a dynamic button label. I tried the following:
echo "<form action='process.php' method='post'>";
echo '<input name="action" type="submit" value="Order New At $" . $new >';
echo '<input name="action" type="submit" value="Order Used At $" . $used >';
echo "</form>";
but all the buttons have on them is the "Order New At $" and "Order Used At $". Is there a way to create a dynamic label on a button?
Dynamic Button Label
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Dynamic Button Label
First off, vars aren't parsed inside of single quotes. Second, you don't have the var inside the quotes for the value, it's just stuck at the end of the tag:
For the future, if both of the buttons have the same name, how will you know which one was clicked?
Code: Select all
echo '<input name="action" type="submit" value="Order New At $' . $new . '">';mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Dynamic Button Label
try this and modify it to your needs
Notice that as AbraCadaver has said I am using different names for each button, in my case the same as the label itself. I also reversed single and double quotes.
Code: Select all
<?php
$buttons = array('HELLO','GOOD BYE', 'ADIOS', 'HOLA');
echo "<form action='process.php' method='post'>";
foreach ($buttons as $row) {
echo "<input name='$row' type='submit' value='$row'>";
}
echo "</form>";
?>Re: Dynamic Button Label
AbraCadaver,
Okay, I tried this:
$sell = '10.47';
$lowest = '3.49';
echo "<form action='process.php' method='post'>";
echo '<input name="New at $sell" type="submit" value="Order New At $sell" >';
echo '<input name="Used at $lowest" type="submit" value="Order Used Starting At $lowest" >';
echo "</form>";
but what it put on the label was "Order New At $sell" rather than "Order New At 10.47". I did change the names of the buttons so you would know I wasn't totally dumb.
Okay, I tried this:
$sell = '10.47';
$lowest = '3.49';
echo "<form action='process.php' method='post'>";
echo '<input name="New at $sell" type="submit" value="Order New At $sell" >';
echo '<input name="Used at $lowest" type="submit" value="Order Used Starting At $lowest" >';
echo "</form>";
but what it put on the label was "Order New At $sell" rather than "Order New At 10.47". I did change the names of the buttons so you would know I wasn't totally dumb.
Re: Dynamic Button Label
manohoo,
Thanks..... I tried your code and it works so I can tailor it from there. Apparently the variable does not have to be inside double quotes!!
Thanks again.
Thanks..... I tried your code and it works so I can tailor it from there. Apparently the variable does not have to be inside double quotes!!
Thanks again.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Dynamic Button Label
Your var is still inside single quotes! Try what I posted and it will work. Read up on it also or it will cause you many problems: http://us2.php.net/manual/en/language.types.string.phpJackD wrote:AbraCadaver,
Okay, I tried this:
$sell = '10.47';
$lowest = '3.49';
echo "<form action='process.php' method='post'>";
echo '<input name="New at $sell" type="submit" value="Order New At $sell" >';
echo '<input name="Used at $lowest" type="submit" value="Order Used Starting At $lowest" >';
echo "</form>";
but what it put on the label was "Order New At $sell" rather than "Order New At 10.47". I did change the names of the buttons so you would know I wasn't totally dumb.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Dynamic Button Label
Thanks, AbraCadaver,
I see what you did now.... when I tried everything inside double quotes I got an error... I did not try single quotes inside double quotes, etc.
I see what you did now.... when I tried everything inside double quotes I got an error... I did not try single quotes inside double quotes, etc.