duanbi7247
2014-03-06 11:00
浏览 90
已采纳

注意:未定义索引:在C:\ xampp \ htdocs \ cars \ index1.php中的elegido在线

i have a dynamic SELECT category menu, i get this error Notice: Undefined index: elegido in C:\xampp\htdocs\cars\index.php on line 30 , 40 & 48 what makes the menu does not work properly.

WHAT IS CAUSING THIS ERROR?

LINES 30, 40 & 48:

 30 if ($_POST["elegido"]==1) {
 40 if ($_POST["elegido"]==2) {
 48 if ($_POST["elegido"]==3) {

HERE IS ALL THE CODE

<script ="javascript">
$(document).ready(function(){
   $("#marca").change(function () {
           $("#marca option:selected").each(function () {
            elegido=$(this).val();
            $.post("modelos.php", { elegido: elegido }, function(data){
            $("#modelo").html(data);
            });            
        });
   })
});
</script>
<p>Marca: 
<select name="marca" id="marca">    
    <option value="1">Renault</option>
    <option value="2">Seat</option>
    <option value="3">Peugeot</option>    
</select></p>
<p>Modelo:
<select name="modelo" id="modelo">    
    <option value="1">4</option>
    <option value="2">5</option>
    <option value="3">7</option>
    <option value="4">21</option>
    <option value="5">Scennic</option>
    <option value="6">Traffic</option>
</select></p>
<?php
$options="";
if ($_POST["elegido"]==1) {
    $options= '
    <option value="1">4</option>
    <option value="2">5</option>
    <option value="3">7</option>
    <option value="4">21</option>
    <option value="5">Scennic</option>
    <option value="6">Traffic</option>
    ';    
}
if ($_POST["elegido"]==2) {
    $options= '
    <option value="1">Ibiza</option>
    <option value="2">Toledo</option>
    <option value="3">Cordoba</option>
    <option value="4">Arosa</option>
    ';    
}
if ($_POST["elegido"]==3) {
    $options= '
    <option value="1">106</option>
    <option value="2">206</option>
    <option value="3">306</option>
    ';    
}
echo $options;    
?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douping3427 2014-03-06 11:02
    已采纳

    try this

    if (isset($_POST["elegido"])) {
    
    //your code
    
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题