Jump to content
DevFuse Forums
najaru

Dropdown in php

Recommended Posts

Hi Michael, hi all

 

I've a simple php code, for take simple data , make calcule, and print the result.

 

here my code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Calcolo</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" >
</head>
<body>
<?php
if (isset ($_POST['val_a']) && isset ($_POST['val_b']) && isset ($_POST['val_c']))
{
$a = (float) $_POST['val_a'];
$b = (float) $_POST['val_b'];
$c = (float) $_POST['val_c'];
$risultato = @($a * $b / $c);
if ($risultato !== FALSE)
echo "Risultato di A*B/C = " . $risultato . "<br><br>";
else
echo "Errore nel calcolo<br><br>";
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>
Valore A <input id="val_a" type="text" name="val_a" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_a'], ENT_QUOTES); ?>">
<br>
Valore B <input id="val_b" type="text" name="val_b" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_b'], ENT_QUOTES); ?>">
<br>
Valore C <input id="val_c" type="text" name="val_c" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_c'], ENT_QUOTES); ?>">
<br>
<input type="submit" value="Calcola">
</p>
</form>
</body>
</html>

i need to multiply the result for a SPECIFIC FACTOR, dependent by value select by user in dropdown

 

 

$risultato = @($a * $b / $c)  * FACTOR;

 

in dropdown for example:

 

RED (FACTOR=1)

GREEN (FACTOR=1,3456)

BLUE (FACTOR=3,2965)

 

then user can choice Red Blue or green in dropdown

 

does is difficult?

Share this post


Link to post
Share on other sites
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Calcolo</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" >
</head>
<body>
<?php

if (isset ($_POST['val_a']) && isset ($_POST['val_b']) && isset ($_POST['val_c']))
{
$a = (float) $_POST['val_a'];
$b = (float) $_POST['val_b'];
$c = (float) $_POST['val_c'];
$risultato = @($a * $b / $c)*$_POST['factor'];
if ($risultato !== FALSE)
echo "Risultato di A*B/C = " . $risultato . "<br><br>";
else
echo "Errore nel calcolo<br><br>";
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p>
Valore A <input id="val_a" type="text" name="val_a" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_a'], ENT_QUOTES); ?>">
<br>
Valore B <input id="val_b" type="text" name="val_b" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_b'], ENT_QUOTES); ?>">
<br>
Valore C <input id="val_c" type="text" name="val_c" size="20" maxlength="20" value="<?php echo htmlspecialchars ($_POST['val_c'], ENT_QUOTES); ?>">
<br>
Factor <select name='factor'><option value='1'>RED</option><option value='1.3456'>GREEN</option><option value='3.2965'>BLUE</option></select>
<br>
<input type="submit" value="Calcola">
</p>
</form>
</body>
</html>

Might want to clean up and test the code a bit but try this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×