tridentmist Posted March 27, 2020 Share Posted March 27, 2020 I'm trying to code a drop-down menu that has four options; one for pie,exp, root 3, and the golden ratio.(all math values) Beside the drop-down menu, there is an option for user-inputted data, they must input only positive numbers. I must take there selected drop-down menu option and times it by the user inputted number. I'm not sure how to check which option the user chose. <form id="s" method="post"> <select id="math" name="options"> <option value="nothing">Please select a constant</option> <option value="pie">Pi</option> <option value="econs">e</option> <option value="ratio">Golden Ratio</option> <option value="root">Root 3</option> </select> <input type="submit" name="Submit" value="Send"> Everything That ive tried has failed Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 27, 2020 Share Posted March 27, 2020 Where is the input value for the user's number? And where is the php code that is processing your html ? Quote Link to comment Share on other sites More sharing options...
tridentmist Posted March 27, 2020 Author Share Posted March 27, 2020 1 minute ago, ginerjm said: Where is the input value for the user's number? And where is the php code that is processing your html ? Honestly, I'm very new to this. this is the most recent code i've created. still doesn't work <?php $choice = $_GET['choice']; ?> <form id="s" method="post"> <label for="first">Constant To be Multiplied: </label> <select id="math" name="options"> <option value="nothing">Please select a constant</option> <option value="pie" <?php if (!empty($choice) && $choice == 'Option1') echo 'selected = "selected"'; ?>>Pi</option> <option value="econs"<?php if (!empty($choice) && $choice == 'Option3') echo 'selected = "selected"'; ?>>e</option> <option value="ratio" <?php if (!empty($choice) && $choice == 'Option3') echo 'selected = "selected"'; ?>>Golden Ratio</option> <option value="root" <?php if (!empty($choice) && $choice == 'Option4') echo 'selected = "selected"'; ?>>Root 3</option> </select> <br> <label for="fname">Number To be Multiplied: </label><input type="text" id="fname" name="value"><br> <input type="submit"> </form> <?php while ($_SERVER["REQUEST_METHOD"] == "POST"){ if (ctype_alpha($_POST["value"])){ echo "Please only input numbers"; exit; } else if (($_POST["value"] <= 0)){ echo "Please Enter Positive numbers only"; exit; } else if ($choicex = 'Option1'){ echo ($_POST['value']*pi()); exit; } else if ($choice = 'Option2'){ echo ($_POST['value']*exp()); exit; } } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 27, 2020 Share Posted March 27, 2020 PUT your php at the start. Save the html for the end. Your php code embedded in the options is wrong the "choice" will be Pi or econs, not Option1 or 2 or 3. Basically , the value value. You will not have a $_GET value. Your form is using POST Quote Link to comment Share on other sites More sharing options...
tridentmist Posted March 27, 2020 Author Share Posted March 27, 2020 (edited) 4 minutes ago, ginerjm said: PUT your php at the start. Save the html for the end. Your php code embedded in the options is wrong the "choice" will be Pi or econs, not Option1 or 2 or 3. Basically , the value value. You will not have a $_GET value. Your form is using POST OK thanks, even when i change the values from "choice" to "pie" and "econs" it only goes to the pie option. How do I make it check to see if "e" was selected. and i fit was, then do the math for that option Edited March 27, 2020 by tridentmist Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 27, 2020 Share Posted March 27, 2020 First change the while to an if. Then put all that at the top of your script and only execute it if your detect that the POST method has been submitted. If not, that's when you fall down to output the html part. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.