简体   繁体   English

单击时禁用值下拉列表

[英]Disable value dropdown list when click

I have code here. 我在这里有代码。 I can see that it's disabling but when it submit data it looks like it was refreshing and the disable value are being reset. 我可以看到它正在禁用,但是当它提交数据时,看起来好像正在刷新并且禁用值正在重置。 What is wrong here? 怎么了 the onclick event is for the radio button for submitting vote. onclick事件用于提交投票的单选按钮。 This dropdown list are fetching data that comes from the database which is position_name 此下拉列表正在获取来自位置为name的数据库的数据

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#position').change(function() {

  $("#position").prop("disabled", true);

});
 });
</script>

and this is the submit dropdown list. 这是提交下拉列表。

      <script type="text/javascript">
   document.getElementById('position_name').value = "<?php echo $_POST['position'];?>";
  </script>
      <div id="container">
       <table width="420" align="center">
        <form name="fmNames" id="fmNames" method="post"  onclick="getPosition(this.value)">
       <tr>
     <td>Choose Position</td>
      <td>
   <SELECT NAME="position" id="position" onchange="form.submit()" onclick="getPosition(this.value)">
       <OPTION VALUE="select">select
       <?php 
          //loop through all table rows
           while ($row=mysql_fetch_array($positions)){
           echo "<OPTION VALUE=$row[position_name]>$row[position_name]"; 

     }
?>
</SELECT></td>
 </tr>
 </form> 

In your SELECT you have an onchange="form.submit()" that triggers the form to submit the data and subsequently redirect to the page it is meant to send the data to which in your case is the same page. 在您的SELECT您具有一个onchange="form.submit()" ,该触发器触发表单提交数据并随后重定向到该页面,这意味着将数据发送到您所在的页面。

Remove the onchange event to stop the form submitting when you select a position. 删除onchange事件,以在您选择职位时停止提交表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM