I want to know what can be the way using php and html such that I am provided a dropdown of books, I need to select exactly two choices out of that drop down and then calculate sum of price of both the books.
Assuming I had hardcoded the Books say:
Book 1 - $5
Book 2 - $15
Book 3 - $50
I know with if it was to select only one book. But no idea for this one. Please help
Code :
<?php
if(isset($_POST['formSubmit']))
{
$varCurrentBook = $_POST['formBook'];
$errorMessage = "";
if(empty($varCurrentBook))
{
$errorMessage = "<li>You forgot to select a Book!</li>";
}
if($errorMessage != "")
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
else
{
switch($varCurrentBook)
{
//Can use here to find what option is clicked
}
exit();
}
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<label for='formBook'>Select a Book</label><br>
<select name="formBook">
<option value="0">Select a Book...</option>
<option value="15">The Secret</option>
<option value="10">The Fairy Tales</option>
<option value="5">All about words</option>
<option value="100">Pinaacle Studio</option>
<option value="120">Harry Potter</option>
<option value="200">Thinking in Java</option>
</select>
<input type="submit" name="formSubmit" value="Submit" />
</form>