如何禁用文本框并为其指定默认值?

时间:2015-05-25 08:16:24

标签: javascript php

这是我的文本框,其id为brgy_name:

 <select name="brgy_name" class="" style="width:240px" id="brgy_name" required >                                                         

                                        <option value="">Select Barangay</option>
                                        <option value="ALL">ALL</option>                                
                                        <?php $result = pg_query("SELECT * FROM tbl_barangay order by cbrgyname");
                                        while($row = pg_fetch_array($result)){ ?>
                                        <option value="<?php echo $row['cbrgyname']; ?>"><font style="margin-top:-20px"><?php echo $row['cbrgyname'];?></font></option>
                                        <?php } ?>

                                           </select>


<input type="hidden" id="asgn_brgy" value="<?php echo $_POST['brgy_name']; ?>">
<input type="hidden" id="frm" value="<?php echo $_POST['fromyear']; ?>">
<input type="hidden" id="to" value="<?php echo $_POST['toyear']; ?>">
<input type="hidden" id="usertype" value="<?php echo $_SESSION['admin_usertype'] ?>"> <!--ADMIN-->
<input type="hidden" id="userbrgy" value="<?php echo $_SESSION['admin_brgycode'] ?>">  <!--TAGUIBO-->

这是我的剧本:

 <script text="text/javascript">
  var holderu = document.getElementById('usertype').value;
  var holderb = document.getElementById('userbrgy').value;
  if(holderu=='ADMIN'){


  }else{

  }

 </script>

如果holderu =='ADMIN'为true ..我想将holderb的值放入文本框中..

3 个答案:

答案 0 :(得分:0)

要添加选项并从中删除一个选项,您可以执行以下操作:

checked

答案 1 :(得分:0)

我希望这会有所帮助..

<script text="text/javascript">
  var holderu = document.getElementById('usertype').value;
  var holderb = document.getElementById('userbrgy').value;
  if(holderu=='ADMIN'){
      $("#brgy_name").empty();
      var select = '<option>'+holderb+'</option>';
      $("#brgy_name").append(select);
      $("#brgy_name").prop('disabled',true);
  }else{
     //your code
  }

答案 2 :(得分:0)

 <script text="text/javascript">
var holderu = document.getElementById('usertype').value;
var holderb = document.getElementById('userbrgy').value;
if(holderu=='ADMIN'){
document.getElementById('brgy_name').innerHTML = ('<option>+holderb+
</option>');

}

else{

}