e^z
06-04-2005, 12:17 AM
I am currently working on a game and I am having problems with a script. I want a form to recognize 2 things while the user is putting info into the form. 1) I want it to recognize a user variable (in this case energy_left) and 2) I want it to recognize how much energy is needed for the workout chosen in the select input. Now I got it to calculate the energy needed for the workout and show the user what it is. And now I want it to show if the user has sufficient energy for the workout. But I cannot get it to work. If I could get some help, that would be great. Thanks.
heres my code:
echo "<form action=school.php?action=work$g_link METHOD=POST name=\"gym\">";
echo "<table border=0 width=86%><tr><td> </td><td>Workout</td><td>Difficulty</td></tr><tr>";
echo "<td><b>Resistance Training</b></td><td><SELECT name=\"res_train\"><option value=\"\">Select Workout<option value=dumb_bells>Dumb Bells<option value=bench>Benchpress<option value=leg_press>Legpress<option value=curls>Curls</select></td><td><SELECT name=\"diff_res\" onFocus=\"startCalc();\" onBlur=\"stopCalc();\">><option>Select Difficulty<option value=0.3>1<option value=0.6>2<option value=0.9>3<option value=1.2>4<option value=1.5>5</select></td></tr><tr>";
echo "<td><b>Cardiovascular Training</b></td><td><SELECT name=\"cardio\"><option value=\"\">Select Workout<option value=bike>Bike<option value=treadmill>Treadmill<option value=skip>Skipping<option value=long_run>Running</select></td><td><SELECT name=\"diff_cardio\" onFocus=\"startCalc();\" onBlur=\"stopCalc();\"><option>Select Difficulty<option value=0.1>1<option value=0.2>2<option value=0.4>3<option value=0.8>4<option value=1.6>5</select></td><input type=text name=test_energy value=\"$user[ene_left]\"></tr><tr>";
?>
<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.gym.diff_res.value;
two = document.gym.diff_cardio.value;
document.gym.tot_energy.value = (one * 1) + (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
</script>
<td colspan=1><b>Energy Required</b></td>
<td colspan=2><input type=text name=tot_energy size=16></td>
</tr>
<tr>
<td colspan=1><b>Sufficient Energy</b></td>
<td colspan=2>
<script type="text/javascript">
if ('document.gym.tot_energy.value' < document.gym.test_energy.value)
{
document.write("<img src=green.gif>");
}
else if ('document.gym.tot_energy.value' > document.gym.test_energy.value)
{
document.write("<img src=red.gif>");
}
else
{
document.write("<img src=yellow.gif>");
}
</script>
</td>
<?
echo "<tr><td><INPUT type=\"submit\" name=\"submit\" value=Submit size=\"14\" maxlength=\"20\"></form></td></tr></table>";
echo "<br><center><a href=school.php?action=gym$g_link>Back</a></center>";
heres my code:
echo "<form action=school.php?action=work$g_link METHOD=POST name=\"gym\">";
echo "<table border=0 width=86%><tr><td> </td><td>Workout</td><td>Difficulty</td></tr><tr>";
echo "<td><b>Resistance Training</b></td><td><SELECT name=\"res_train\"><option value=\"\">Select Workout<option value=dumb_bells>Dumb Bells<option value=bench>Benchpress<option value=leg_press>Legpress<option value=curls>Curls</select></td><td><SELECT name=\"diff_res\" onFocus=\"startCalc();\" onBlur=\"stopCalc();\">><option>Select Difficulty<option value=0.3>1<option value=0.6>2<option value=0.9>3<option value=1.2>4<option value=1.5>5</select></td></tr><tr>";
echo "<td><b>Cardiovascular Training</b></td><td><SELECT name=\"cardio\"><option value=\"\">Select Workout<option value=bike>Bike<option value=treadmill>Treadmill<option value=skip>Skipping<option value=long_run>Running</select></td><td><SELECT name=\"diff_cardio\" onFocus=\"startCalc();\" onBlur=\"stopCalc();\"><option>Select Difficulty<option value=0.1>1<option value=0.2>2<option value=0.4>3<option value=0.8>4<option value=1.6>5</select></td><input type=text name=test_energy value=\"$user[ene_left]\"></tr><tr>";
?>
<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.gym.diff_res.value;
two = document.gym.diff_cardio.value;
document.gym.tot_energy.value = (one * 1) + (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
</script>
<td colspan=1><b>Energy Required</b></td>
<td colspan=2><input type=text name=tot_energy size=16></td>
</tr>
<tr>
<td colspan=1><b>Sufficient Energy</b></td>
<td colspan=2>
<script type="text/javascript">
if ('document.gym.tot_energy.value' < document.gym.test_energy.value)
{
document.write("<img src=green.gif>");
}
else if ('document.gym.tot_energy.value' > document.gym.test_energy.value)
{
document.write("<img src=red.gif>");
}
else
{
document.write("<img src=yellow.gif>");
}
</script>
</td>
<?
echo "<tr><td><INPUT type=\"submit\" name=\"submit\" value=Submit size=\"14\" maxlength=\"20\"></form></td></tr></table>";
echo "<br><center><a href=school.php?action=gym$g_link>Back</a></center>";