Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/310391-drop-down-menu-php/
Share on other sites

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;
    
}

}
?>

Link to comment
https://forums.phpfreaks.com/topic/310391-drop-down-menu-php/#findComment-1575921
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/310391-drop-down-menu-php/#findComment-1575923
Share on other sites

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 by tridentmist
Link to comment
https://forums.phpfreaks.com/topic/310391-drop-down-menu-php/#findComment-1575926
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.