I am creating a simple VAT calculator and am having a problem with the drop list options. The two option are $vatincluded & $vatexcluded. If $vatincluded is selected a simple calculation is made and if $vatexcluded is selected the ammount input is left as is. I gather I would need to set a Boolean to check is $vatincluded has been selected in the drop list but unsure how to add to the script. Can anyone point me in the right direction.
Many Thanks in advance...
<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$ammount = $_POST['ammount'];
$vatincluded = $_POST['vatincluded'];
$vatexcluded = $_POST['vatexcluded'];
if ($vatincluded) {
$netammount = ($ammount / 120 * 100);
}
else
{
$netammount = $ammount;
$vatammount = ($netammount * 0.20);
$grossammount = ($netammount + $vatammount);
}
echo 'Thanks for submitting the form.<br />';
echo 'Net Ammount £: ' . $netammount . '<br />';
echo 'Vat Ammount £: ' . $vatammount . '<br />';
echo 'Gross Ammount £: ' . $grossammount . '<br />';
echo 'Your first name ' . $first_name . '<br />';
echo 'Your last name: ' . $last_name . '<br />';
echo 'Your email address is ' . $email;
?>
If you by dropdown list
you mean a select element.
You can do something like:
HTML
<select name="vat">
<option value="yes">Include</option>
<option value="no">Not included</option>
</select>
PHP
if ($_POST['vat'] == 'yes') {
// vat include
} else {
// vat excluded
}