2014-07-22 21:31
浏览 67


I have this dropdown menu and I want people to be able to add a new category if they do not find it on the menu, but I want the form hidden unless they select 'Outro'. If they do then it should be displayed. but I haven't been able to make it change depending on the answer. What am I doing wrong?

here's the code:

 echo '<form name="display_Info" action="" method="post">';
 echo '<select name="selected_Category" id="selected_Category">';
 echo'<option value="0" label="coyvalue" selected="selected"> Escolha sua Categoria </option>';

 while ($row = mysqli_fetch_array($BC_SQLselect_Query, MYSQLI_ASSOC)){
        $BC_ID = $row['BC_ID'];
        $BC_Categories = $row['BC_Categories'];
        echo '<option value"'.$BC_ID.'">'.$BC_Categories.'</option>';

 $selected_Category = $_POST['selected_Category'];
 echo '</select></br>';

 if ($selected_Category !== 'Outro'){
        $BC_New_Category = $row['BC_Categories'];
        echo'Adicione Nova Categoria: </br>
            <input type="text" name="BC_New_Category" value="'.$BC_New_Category.'"/>';
        echo '<option value"'.$BC_ID.'">'.$BC_New_Category.'</option>';
        $BC_Category_Update = 'INSERT INTO business_categories(BC_Categories) VALUES ('.$BC_New_Category.')';
 } else {
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douqin7086 2014-07-22 21:41

    Have a look at this:

    <option value="0" label="coyvalue" selected="selected"> Escolha sua Categoria </option>

    You basically "hardcode" the selected value to be 0, so it will never be equal to 'Outro'.

    Edited: just for the sake of a complete answer, and full credit goes to @Fred-ii- who pointed this out in his comment, you should probably also replace this...

    echo '<option value"'.$BC_ID.'">'. /*...*/ .';

    with this...

    echo '<option value="'.$BC_ID.'">'. /*...*/ .';

    You were missing an equial sign after the value attribute.

    解决 无用
    打赏 举报

相关推荐 更多相似问题