选择菜单,使用所选内容的变量

I'm fairly new to php, and coding in general.

I have a site where I will be having a horse trained. In the sql database I have a variable for how much they've been tamed, and when it's 100 it will stop. But the user can select from a drop down menu how long they'd like to tame the horse from 30 mins-4 hours. Each full hour is a full point towards the taming and a half point is worth .5. I want another variable that decreases the energy. For every 30 minutes it would decrease the energy by 5%. So I'd multiply whatever they chose by 10.

How do I get it to where it knows what the user selects and to then use that as what's updated in the value field?

This is the code I have:

<form id="Update" name="Update" method="POST" action="<?php echo   $editFormAction; ?>">
    <input type="submit" name="Tame" id="Tame" value="Tame" />
    <select name="Hours">
      <option value=".5">30 mins</option>
      <option value="1">1 hour</option>
      <option value="1.5">1 hour 30 mins</option>
      <option value="2">2 hours</option>
      <option value="2.5">2 hours 30 mins</option>
      <option value="3">3 hours</option>
      <option value="3.5">3 hours 30 mins</option>
      <option value="4">4 hours</option>
    </select>
    <input name = "Energy" type = "hidden" id = "EnergyDown" value = ""
    <input name="Date" type = "hidden" id = "Date" value= "<?php echo $RealDate ?>"/>
    <input type="hidden" name="MM_update" value="Update" />
    <input name="HorseId" type="hidden" id="HorseId" value="<?php echo $colname_HorseInfo ?> ">

</form>

I'm assuming you want to update the value of the input with the name "Energy"?

If so, you could do the following with javascript (just put it in the head part of the website, inside script tags.)

Firstly set an ID & onchange in the , so:

<select id="hours" name="Hours" onchange="setEnergy(this)">

Overall the javascript will look like this:

<head>
<script>
function setEnergy(x){
    //Get the value of the currently selected option
    var y = x[x.selectedIndex].value;

    //Multiply the value by 10
    var result = y * 10;

    //Change the value of the Energy input
    var energydown = document.getElementById("EnergyDown");
    energydown.value = result;
}
</script>
</head>

Also don't forget to set a default value. Your select tags will default to 30 mins, so the value should be set to 5 to account for this.

If you change the input type from "hidden" to "text" when you test this, you'll be able to see it changing.

Good luck, hope this helps!

-Edit

I was just out walking and realised that yeah, you could just submit it and work on it with PHP, but now you also know the javascript method; it will help you do live-updates on the client's page if necessary (which is what you asked for). :)

You do not need the hidden INPUT.

When the form is submitted you then calculate the Energy from the Number of Hours submitted.

$hours = floatval($_POST['Hours']);
$energyDown = $hours * .05;