如何在 php 中选择一个时禁用下拉列表

How to disable drop down when selecting one in php

本文关键字:一个 下拉列表 php 选择      更新时间:2023-10-27

有人可以帮我修复我的代码吗?我的问题是如何在选择一个投递箱时禁用另一个投递箱?我正在使用PHP和JavaScript编程语言。我希望任何人都可以帮助我,因为这非常重要。

这是我的代码:

    <head>
           <script type = "text/javascript">
            function disableDrop(){
           if(frmMain.sltMain.options[1].selected){
                 frmMain.sltSecondary.disabled = true;
              }
              else{
                 frmMain.sltSecondary.disabled = false;
                }
              }
                   </script>
        </head>
         <form ID = "frmMain">
      <select ID = "sltMain" onchange = "disableDrop();">
         <option value = "onetime" selected>One-Time</option>
         <option value = "recurring">Recurring</option>
           </select>
         <select ID = "sltMain" onchange = "disableDrop();">
           <option value = "onetime">One-Time</option>
        <option value = "recurring" selected>Recurring</option>
         </select>
             </form>

试试这个 : 演示

网页编码 :

  <select ID = "sltMain" onchange = "disableDrop(this);">
     <option value = "onetime" selected>One-Time</option>
     <option value = "recurring">Recurring</option>
       </select>
     <select ID = "sltSecondary" onchange = "disableDrop1(this);">
       <option value = "onetime">One-Time</option>
    <option value = "recurring" selected>Recurring</option>
     </select>
         </form>

JAVASCRIPT:

function disableDrop(elem) {
    if(elem.value == 'recurring'){
    document.getElementById('sltSecondary').disabled = true;
    }
    else{
     document.getElementById('sltSecondary').disabled = false;        
    }
}
function disableDrop1(elem) {

    if(elem.value == 'onetime'){
    document.getElementById('sltMain').disabled = true;
    }
    else{
     document.getElementById('sltMain').disabled = false;        
    }
}

是 "sltsecondary" ID 吗?

第二项具有相同的ID,我想你的意思

     <form ID = "frmMain">
  <select ID = "sltMain" onchange = "disableDrop();">
     <option value = "onetime" selected>One-Time</option>
     <option value = "recurring">Recurring</option>
       </select>
     <select ID = "sltSecondary" onchange = "disableDrop();">
       <option value = "onetime">One-Time</option>
    <option value = "recurring" selected>Recurring</option>
     </select>
         </form>
相关文章: