So I know theres a 100% way to do this, but I don't think I'm doing it right. Pretty much this is what my goal for this code is.
I want the user to be able to select an amount of time in intervals of 30 minutes up to 5 hours. (theres 10 options then) Each 30 min interval adds another .5 to a variable lets call D.
Variable I, E, and T rely on Variable D.
I currently have a drop down that has a javascript on change. But after that I need to update a record in my MYSQL server with Variable D, I,E and T.
This is the code I have so far:
<form name="Tame" method="POST">
<select id="VariableD" onchange="myFunction()">
<option value=".5">30 mins
<option value="1">1 hour
<option value="1.5">1 hour 30 mins
<option value="2">2 hours
<option value="2.5">2 hour 30 mins
<option value="3">3 hour
<option value="3.5">3 hours 30 mins
<option value="4">4 hours
<option value="4.5">4 hours 30 mins
<option value="5">5 hour
</select>
<input type="hidden" name="VariableI" value="2">
<input type="hidden" name="VariableT" value="4">
<input type="hidden" name="VariableE" value="10">
<input type="submit" name="TameSub" value="Tame">
</form>
Then I have my JavaScript:
<script>
function myFunction() {
var x = document.getElementById("VariableD").value;
var TameEnergy = x * 10;
var TameIntell = x * 2;
var TameGain = x * 4;
var En = document.getElementById("VariableE");
var Intell = document.getElementById("VariableI");
var Tame = document.getElementById("VariableE");
En.value = TameEnergy;
Intell.value = TameIntell;
Tame.value = TameGain;
}
</script>
And after I have my script to determine all my variables I have this for PHP to update the record:
<?php
$SubTame = $_POST['TameSub'];
$I = $_POST['VariableI'];
$E = $_POST['VariableE'];
$T = $_POST['VariableT'];
if($SubTame) {
$sql = "UPDATE Horse SET Energy='$E', IntelligenceP='$I', Taming='$T' WHERE id='$colname_HorseInfo'";
if ($con->query($sql) === TRUE) {
?>
<script>location.reload();</script>
<?php
} else {}
}
?>
When I do it this way I have the record updating but it only updates by the default values I have in the form, meaning that any of the change within the JavaScript doesn't get recognised when updating. I'm willing to do this with AJAX if someone could explain to me how I would do it in this situation.