<span>Level</span><br>
<select name="exp" id="exp" required>
<option disabled selected hidden>Choose your level</option>
<option>without exp</option>
<option>up to 1 month</option>
<option>up to 3 months</option>
<option>up to 6 months</option>
<option>1 year or more</option>
</select>
PHP:
$exp = "";
if(!empty($_POST)){
$exp = $_POST['exp']; //here I get only the value??
calcularIMC($exp);
}
function calcularIMC($exp){ // comparisons I want to do
if($exp == "INDEX 0"){ ...... } // how I can get the value to do this comparations?
if($exp >= "INDEX 1"){ ...... }
}
对于测试我做了变量$exp
以字符串的形式存储。我想知道如何在上面的例子中得到索引进行比较。
如何获取select的索引?
答案 0 :(得分:3)
您需要为选项设置值,然后这些值将是提交给您服务器的值。
<select name="exp" id="exp" required>
<option disabled selected hidden>Choose your level</option>
<option value="0">without exp</option>
...
</select>