【问题标题】:how dynamic dropdown set select use动态下拉集如何选择使用
【发布时间】:2018-01-25 06:18:54
【问题描述】:

我正在这样做。这是我从数据库结果中填充的动态下拉列表。当我提交表单时,应用验证,如果在空字段上发生验证错误,表单将停止提交。但是所有下拉菜单也会删除它的值,所以我再次填写所有表单而不是空白字段

我之前的代码是:apply set select之前

<select name="position_filled_against_id" id="position_filled_against_id">
 <option value="">Select</option>
<?php
foreach($position_filled_against as $position_filled)
{
 $selected = "";
 echo '<option value="'.$position_filled->position_filled_against_id.'" >'.$position_filled->code.'-'.$position_filled->name.'</option>';
}
?>
</select>

应用集选择后:但语法错误

<select name="position_filled_against_id" id="position_filled_against_id"><option value="">Select</option>
<?php
  foreach($position_filled_against as $position_filled)
  {
     $selected = "";
     echo '<option value="'.set_select("position_filled_against_id",$position_filled->position_filled_against_id,TRUE).'" >'.$position_filled->code.'-'.$position_filled->name.'</option>';
  }
  ?>
</select>

【问题讨论】:

  • 它只给出语法错误。我想在验证应用后设置下拉列表的值
  • 但没有显示错误
  • 您需要您的建议,您是否愿意对我的代码做同样的事情,因为我有语法错误

标签: php codeigniter


【解决方案1】:

你可以试试下面的代码,它会帮助你

<select name="position_filled_against_id" id="position_filled_against_id">
<option value="">Select</option>
<?php
foreach($position_filled_against as $position_filled)
{
 $selected = "";
 if($_REQUEST['position_filled_against_id']==$position_filled->position_filled_against_id)
 {
   $selected = 'selected="selected"';
 }
 echo '<option value="'.$position_filled->position_filled_against_id.'" '.$selected.' >'.$position_filled->code.'-'.$position_filled->name.'</option>';
}
?>
</select>

【讨论】:

    【解决方案2】:

    我删除了语法错误

    <select name="position_filled_against_id" id="position_filled_against_id">
    <option value="">Select</option>
    <?php
    
        foreach($position_filled_against as $position_filled)
        {
         $selected = "";
         echo '<option value="'.$position_filled->position_filled_against_id.'" '.set_select("position_filled_against_id","$position_filled->position_filled_against_id", TRUE).' >'.$position_filled->code.'-'.$position_filled->name.'</option>';
         }
    ?>
    </select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-04
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 2013-07-09
      相关资源
      最近更新 更多