HTML选择表单无效 [英] HTML select form not working

查看:92
本文介绍了HTML选择表单无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网站: http://macrorevolution.com/calculators/tdee/
嘿我试图创建一个简单的计算器,但遇到了一些问题。



首先,我的HTML选择表单似乎没有效果。我的目标是让选择输入更改$ activelevel的值。例如,如果用户选择重度运动,那么1.9的 $ activelevel 将应用于我的公式。

第二,我想要以粗体显示输出$答案。我尝试过:
<?php echo< b>。$ answer。< / b> ?> <?php echo< span class =bold> $ answer< / span> ?> 但他们都失败。我认为这是因为他们在 value =''



最后,我的最后一张桌子没有可见即使我设置了border =1?

 <?php 
$ answer =;
$ agev =;
$ feetv =;
$ inchesv =;
$ weightv =;
$ sex =;
$ activelevel =;
if(isset($ _ POST ['agev'])& isset($ _ POST ['feetv'])& isset($ _ POST ['inchesv'])&& isset $ _POST ['weightv'])&& isset($ _ POST ['sex'])){
//&& isset($ _ POST ['activelevel'])
$ agev = $ _POST ['agev'];
$ feetv = $ _POST ['feetv'];
$ inchesv = $ _POST ['inchesv'];
$ weightv = $ _POST ['weightv'];
$ sex = $ _POST ['sex'];
$ activelevel = $ _POST ['activelevel'];
$ totalheightv = $ inchesv +($ feetv * 12);
$ heightcm = $ totalheightv * 2.54;
$ weightkg = $ weightv / 2.2;

echo $ activelevel;
if($ activelevel =='1v')$ activelevel = 1.2;
else if($ activelevel =='2v')$ activelevel = 1.375;
else if($ activelevel =='3v')$ activelevel = 1.55;
else if($ activelevel =='4v')$ activelevel = 1.725;
else if($ activelevel =='5v')$ activelevel = 1.9;
else echoerror;
// echo $ activelevel;
$ b $ if($ sex =='male')$ answer = $ activelevel *(66.47 +(13.75 * $ weightkg)+(5 * $ heightcm) - (6.75 * $ agev));
if($ sex =='female')$ answer = $ activelevel *(665.09 +(9.56 * $ weightkg)+(1.84 * $ heightcm) - (4.67 * $ agev));

}
?>


<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< title>每日总能量支出< / title>

< style type =text / css>
.bold {
font-weight:bold;
}
< / style>

< style>
table {
font-size:14px;
font-family:'PT Sans',sans-serif;
背景颜色:#FFFFFF;
}
tr.spaceUnder> td
{
padding:0em 1em 1em 0em;

}
p.ss {
font-size:30px;
text-align:center
}
input {
margin-right:5px;
margin-left:5px;
}

< / style>
< / head>
< body>
< div class =box pt20>
< p class =ss> MacroRevolution TDEE计算器< / p>< br>
< table width = '80%'style =margin:0 auto;>
< tr class =spaceUnder>
< td colspan =4>
TDEE =每日总能量支出。 TDEE是你的身体在24小时内燃烧的卡路里,包括进食,睡眠,锻炼和工作。
< / td>
< / tr>
< / table>

< form method ='post'action =''>
< table width = '80%'style =margin:0 auto;>


< tr class =spaceUnder>
< td>年龄:< / td>
< td>< input type ='text'name ='agev'value =<?php echo $ agev;?>/>年度< / td>
< / tr>
< tr class =spaceUnder>
< td>身高:< / td>
< td align =justify>< input type ='text'name ='feetv'value =<?php echo $ feetv;?>/> Ft

< input type ='text'name ='inchesv'value =<?php echo $ inchesv;?>/> In< / td>
< / tr>
< tr class =spaceUnder>
< td>重量:< / td>
< td align =left>< input type ='text'name ='weightv'value =<?php echo $ weightv;?>/> lbs< / td>
< / tr>
< tr class =spaceUnder>
< td colspan =2>< input type ='radio'name ='sex'value ='male'> Male
< input type ='radio'name =' sex'value ='female'>女性< / td>
< / tr>
< tr class =spaceUnder>
< td colspan =2>
< select>
< option name ='activelevel'value ='1v'>很少或没有运动/桌面工作< / option>
< option name ='activelevel'value ='2v'>轻度运动/锻炼1-3天/周< / option>
< option name ='activelevel'value ='3v'>适度锻炼/锻炼3-5天/周< / option>
< option name ='activelevel'value ='4v'>重度运动/锻炼6-7天/周< / option>
< option name ='activelevel'value ='5v'>非常繁重的运动/身体锻炼/每天锻炼2次< / option>
< / select>
< / td>
< / tr>

< tr class =spaceUnder>
< td colspan =2>< input type ='submit'class =button highlight smallvalue ='Calculate'/>< / td>
< / tr>
< tr class =spaceUnder>
< td colspan =2>您的TDEE是< input type ='text'style =width:50px; value ='<?php echo $ answer?>'/>< strong> k / cal每天< / strong> < / TD>
< / tr>

< / table>
< / form>


< table border ='0'width = '80%'style =margin:0 auto;>
< td colspan =4>


TDEE = BMR x活动等级< br>
当BMR(Harris-Benedict公式)的公式为< br>< br>
Men:BMR = 66.47 +(13.75×W)+(5.0×H) - (6.75×A)< br>
女性:BMR = 665.09 +(9.56×W)+(1.84×H) - (4.67×A)< br>

W =以千克计的重量(磅/2.2)< br>
H =厘米高度(英寸x 2.54)< br>
A =以年为单位的年龄< br>< br>< br>

< table border =1width ='500px'>
< tr>
< th>活动量< / th>
< th>说明< / th>
TDEE活动等级< / th>
< / tr>
< tr>
< td>久坐不动< / td>
< td>很少或没有运动/桌面工作< / td>
< td> 1.2< / td>
< / tr>
< tr>
< td>轻微活动< / td>
< td>轻度运动/锻炼1-3天/周< / td>
< td> 1.375< / td>
< / tr>
< tr>
< td>中等活动< / td>
< td>适度锻炼/锻炼3-5天/周< / td>
< td> 1.55< / td>
< / tr>
< tr>
< td>非常活跃< / td>
< td>重度运动/锻炼6-7天/周< / td>
< td> 1.725< / td>
< / tr>
< tr>
< td>极度活跃< / td>
< td>非常沉重的运动/身体锻炼/每天锻炼2次< / td>
< td> 1.9< / td>
< / tr>
< / table>
< br>< br>< br>
< / td>
< / table>
< / div>

< / body>
< / html>


解决方案

您的选择输入需要设置名称。考虑:

 < select name =activelevel> 
< option value ='1v'>很少或没有运动/桌面工作< / option>
< option value ='2v'>轻度运动/锻炼1-3天/周< / option>
< option value ='3v'>适度锻炼/锻炼3-5天/周< / option>
< option value ='4v'>剧烈运动/锻炼6-7天/周< / option>
< option value ='5v'>非常沉重的运动/身体锻炼/每天锻炼2次< / option>
< / select>

您可以通过设置输入框的字体重量样式将答案设置为粗体。 / p>

 < input type ='text'style =width:50px; font-weight:bold; value ='<?php echo $ answer?>'/> 

您的表格边框由文件style.css设置为:

 表{
border-collapse:collapse;
border-spacing:0;
}


site: http://macrorevolution.com/calculators/tdee/ Hey I'm trying to create a simple calculator but am running into a few problems.

First, my HTML select form seems to have no effect. My goal is to have the select input change the value of $activelevel. For example, if the user chooses 'heavy exercise, then an $activelevel of 1.9 will be applied to my formula.

Second, I want to bold the output $answer in . I've tried doing: <?php echo "<b>".$answer."</b>" ?> and <?php echo <span class="bold">$answer</span> ?> but they both fail. I think it's because they are in value=' '?

Lastly, how come my last table has no visible border even though I set border="1"?

<?php
$answer = "";
$agev = "";
$feetv = "";
$inchesv = "";
$weightv = "";
$sex = "";
$activelevel = "";
if(isset($_POST['agev']) && isset($_POST['feetv']) && isset($_POST['inchesv']) && isset($_POST['weightv']) && isset($_POST['sex'])) {
    //&& isset($_POST['activelevel'])
    $agev = $_POST['agev'];
    $feetv = $_POST['feetv'];
    $inchesv = $_POST['inchesv'];
    $weightv = $_POST['weightv'];
    $sex = $_POST['sex'];
    $activelevel = $_POST['activelevel'];
    $totalheightv = $inchesv + ($feetv*12);
    $heightcm = $totalheightv*2.54;
    $weightkg = $weightv/2.2;

    echo $activelevel;
    if($activelevel=='1v') $activelevel=1.2;
    else if($activelevel=='2v') $activelevel=1.375;
    else if($activelevel=='3v') $activelevel=1.55;
    else if($activelevel=='4v') $activelevel=1.725;
    else if($activelevel=='5v') $activelevel=1.9;
    else echo "error";
    //echo $activelevel;

    if($sex=='male') $answer = $activelevel * (66.47 + (13.75*$weightkg) + (5*$heightcm) - (6.75*$agev));
    if($sex=='female') $answer = $activelevel * (665.09 + (9.56*$weightkg) + (1.84*$heightcm) - (4.67*$agev));

}
?>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>Total Daily Energy Expenditure</title>

<style type="text/css">
.bold {
font-weight:bold;
}
</style>

<style>
  table {
    font-size:14px;
    font-family: 'PT Sans', sans-serif;
    background-color:#FFFFFF;
  }
tr.spaceUnder > td
{
  padding:0em 1em 1em 0em;

}
p.ss {
    font-size:30px; 
    text-align:center
}
input {
margin-right:5px;
margin-left:5px;
}

</style>
</head>
<body>
<div class="box pt20">
<p class="ss">MacroRevolution TDEE Calculator</p><br>
<table width='80%' style="margin: 0 auto;">
    <tr class="spaceUnder">
    <td colspan="4">
TDEE = Total Daily Energy Expenditure. TDEE is the amount calories your body burns in a 24 hour period which includes eating, sleeping, excercising, and working.
    </td>
    </tr>
</table>

<form method='post' action=''>
<table width='80%' style="margin: 0 auto;">


    <tr class="spaceUnder">
        <td>Age:</td>
        <td><input type='text' name='agev' value="<?php echo $agev; ?>"/>Years</td>
    </tr>
    <tr class="spaceUnder">
        <td>Height:</td>
        <td align="justify"><input type='text' name='feetv' value="<?php echo $feetv; ?>"/>Ft

        <input type='text' name='inchesv' value="<?php echo $inchesv; ?>"/>In</td>
    </tr>
    <tr class="spaceUnder">
        <td>Weight:</td>
        <td align="left"><input type='text' name='weightv' value="<?php echo $weightv; ?>"/>lbs</td>
    </tr>
    <tr class="spaceUnder">
        <td colspan="2"><input type='radio' name='sex' value='male'>Male
                        <input type='radio' name='sex' value='female'>Female</td>
    </tr>
        <tr class="spaceUnder">
    <td colspan="2">
        <select>
  <option name='activelevel' value='1v'>Little or no Excercise / Desk job</option>
  <option name='activelevel' value='2v'>Light exercise / Workout 1-3 days/week</option>
  <option name='activelevel' value='3v'>Moderate exercise / Workout 3-5 days/week</option>
  <option name='activelevel' value='4v'>Heavy exercise / Workout 6-7 days/week</option>
  <option name='activelevel' value='5v'>Very heavy exercise / Physical job / Workout 2 times a day</option>
         </select>
        </td>
        </tr>

    <tr class="spaceUnder">
        <td colspan="2"><input type='submit' class="button highlight small" value='Calculate'/></td>
    </tr>
    <tr class="spaceUnder">
        <td colspan="2">Your TDEE is <input type='text' style="width: 50px;" value='<?php echo $answer?>' /><strong>k/cal per day</strong>  </td>
    </tr>

</table>
</form>


<table border='0' width='80%' style="margin: 0 auto;">
    <td colspan="4">


        TDEE = BMR x Activity Level <br>
    Where the formula for BMR(Harris-Benedict formula) is <br><br>
Men: BMR=66.47+ (13.75 x W) + (5.0 x H) - (6.75 x A) <br>
Women: BMR=665.09 + (9.56 x W) + (1.84 x H) - (4.67 x A) <br><br>

    W = Weight in kilograms (lbs/2.2)<br>
    H = Height in centimeters (inches x 2.54)<br>
    A = Age in years <br><br><br>

        <table border="1" width='500px'>
    <tr>
    <th>Amount of Activity</th>
    <th>Description</th>
    <th>TDEE Activity Level</th>
    </tr>
    <tr>
    <td>Sedentary</td>
    <td>Little or no Excercise / Desk job</td>
    <td>1.2</td>
    </tr>
    <tr>
    <td>Lightly Active</td>
    <td>Light exercise / Workout 1-3 days/week</td>
    <td>1.375</td>
    </tr>
    <tr>
    <td>Moderately Active</td>
    <td>Moderate exercise / Workout 3-5 days/week</td>
    <td>1.55</td>
    </tr>
    <tr>
    <td>Very Active</td>
    <td>Heavy exercise / Workout 6-7 days/week</td>
    <td>1.725</td>
    </tr>
    <tr>
    <td>Extremely Active</td>
    <td>Very heavy exercise / Physical job / Workout 2 times a day</td>
    <td>1.9</td>
    </tr>
    </table>  
    <br><br><br>
    </td>
</table>
</div>

</body>
</html>

解决方案

Your select input needs to have the name set. Consider:

<select name="activelevel">
<option value='1v'>Little or no Excercise / Desk job</option>
<option value='2v'>Light exercise / Workout 1-3 days/week</option>
<option value='3v'>Moderate exercise / Workout 3-5 days/week</option>
<option value='4v'>Heavy exercise / Workout 6-7 days/week</option>
<option value='5v'>Very heavy exercise / Physical job / Workout 2 times a day</option>
</select>

You can set the answer to be bold by setting the font-weight style of the input box.

<input type='text' style="width: 50px;font-weight:bold;" value='<?php echo $answer?>' />

Your table border is set by the file style.css to:

table {
border-collapse: collapse;
border-spacing: 0;
}

这篇关于HTML选择表单无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆