duanci1939
2015-07-08 21:54
浏览 35
已采纳

使用onchange函数PHP,JAVASCRIPT时,选择列表会忽略第一个值

I'm using a select list function below to make a select list that have 5 values inside of it. Values 2-5 works fine when I select them, and they print out their values on the page when I select them, but value 1 does not print out no matter what. I cannot figure out what I did wrong or how to fix it. Please take a look at my code:

index.php

function limit($count,$location) {

echo "<form method = 'POST' action = '$location'>";
echo "<select name = 'value' onchange='this.form.submit()'>";

while ($tempCount < $count) {
$tempCount++;
echo "<option value='$tempCount'>$tempCount</option>";
}

echo "</select>";
echo "</form>";

}

limit(5,"index.php")

$value = $_POST['value'];
echo $value;

图片转代码服务由CSDN问答提供 功能建议

我正在使用下面的选择列表功能来制作一个包含5个值的选择列表。 当我选择它们时,值2-5工作正常,当我选择它们时,它们会在页面上打印出它们的值,但无论如何,值1都不会打印出来。 我无法弄清楚我做错了什么或如何解决它。 请看一下我的代码:

index.php

 功能限制($ count,$  location){
 
echo“&lt; form method ='POST'action ='$ location'&gt;”; 
echo“&lt; select name ='value'onchange ='this.form.submit()'&gt;  “; 
 
而($ tempCount&lt; $ count){
 $ tempCount ++; 
echo”&lt; option value ='$ tempCount'&gt; $ tempCount&lt; / option&gt;“; 
} 
 
echo”  &lt; / select&gt;“; 
echo”&lt; / form&gt;“; 
 
} 
 
limit(5,”index.php“)
 
 $ value = $ _POST ['value'];  
echo $ value; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题