简体   繁体   English

如何根据是否通过jsp中的jstl检查单选按钮启用和禁用下拉列表

[英]how to enable and disable a dropdown list based on whether a radio button is checked or not through jstl in jsp

In jsp page I have two radio button,if I check a radio button then one dropdown list should be enabled and if I select another radio button then another drop down list should be enabled and first dropdown list should be disabled.If none of the radio buttons are selected then both the drop down should be disbaled. 在jsp页面中,我有两个单选按钮,如果我选中一个单选按钮,则应启用一个下拉列表,如果我选择另一个单选按钮,则应启用另一个下拉列表,并且应禁用第一个下拉列表。按钮被选中,那么两个下拉菜单都将被取消显示。 How to do it using or tags of jstl.I tried in thsi way,but no results 我用这种方式尝试过,但没有结果

<b>Select Status</b>
<p><input type="radio" name="val" value="Filling" id="Filling"> Filling</p>
<p><input type="radio" name="val" value="Stored" id="stored"> Stored</p>
<c:choose>
<c:when test="${Filling}">
Select Reference:
<select name="ref_logtime" >
<option value="Select">Select</option>
<c:forEach var="aff" items="${obj.connect()}">
<option value="${aff.value}">${aff.key} ${aff.value}</option>
</c:forEach>
</select>
</c:when>
<c:otherwise>
Select Reference:
<select name="ref_logtime" >
<option value="Select">Select</option>
<c:forEach var="aff" items="${obj.connect()}">
<option value="${aff.value}">${aff.key} ${aff.value}</option>
</c:forEach>
</select>
</c:otherwise>
</c:choose>

EDIT- How to do it through javascript ,if it can't be done with jstl. 编辑-如果无法通过jstl完成,则如何通过javascript进行操作。

<script type="text/javascript">

$(document).ready(function(){
    $('input[name="val"]').click(function() {
       if($('input[name="val"]').is(':checked')) { 
           var radioValue = $("input[name='val']:checked").val();
            if(radioValue == "Filling"){
               $( "#Fill" ).prop( "disabled", false );
               $( "#stored" ).prop( "disabled", true );
            } else {
                $( "#Fill" ).prop( "disabled", true );
               $( "#stored" ).prop( "disabled", false );
            }
       }
    });
    });
</script>
</head>

</head>

<body>
<jsp:useBean id="obj"  class="ref_Database.Refernce_Database" />


<form method="post" action="All_Mps.jsp">
<b>Select Status</b>
<p><input type="radio" name="val" value="Filling" id="Filling"> Filling</p>
<p><input type="radio" name="val" value="Stored" id="stored"> Stored</p>


Select Reference:
<select name="ref_fill" id="Fill" disabled="disabled" >
<option value="Select">Select</option>
<c:forEach var="aff" items="${obj.connect()}">
<option value="${aff.value}">${aff.key} ${aff.value}</option>
</c:forEach>
</select>

Select Reference:
<select name="ref_stored" id="stored" disabled="disabled" >
<option value="Select">Select</option>
<c:forEach var="aff" items="${obj.connect()}">
<option value="${aff.value}">${aff.key} ${aff.value}</option>
</c:forEach>
</select>

<br><br>
<b>Select Date to be compared</b><br>
<p>

In HTML use like this, 在HTML中这样使用

<input type="radio" name="gender" value="m" />Male
<input type="radio" name="gender" value="f" />Female
<br />
<select id="mOptions" disabled="true">
    <option>Select</option>
    <option value="1">Shirt</option>
    <option value="2">Pant</option>
    <option value="3">dhoti</option>
</select>

<select id="fOptions" disabled="true">
    <option>Select</option>
    <option value="4">Saree</option>
    <option value="5">Bangle</option>
   <option value="6">handbag</option>
</select>

And in scripting i have used the jQuery library, 在脚本编写中,我使用了jQuery库,

$(document).ready(function(){
$('input[name="gender"]').click(function() {
   if($('input[name="gender"]').is(':checked')) { 
       var radioValue = $("input[name='gender']:checked").val();
        if(radioValue == "m"){
           $( "#mOptions" ).prop( "disabled", false );
           $( "#fOptions" ).prop( "disabled", true );
        } else {
            $( "#mOptions" ).prop( "disabled", true );
           $( "#fOptions" ).prop( "disabled", false );
        }
   }
});
});

Please find the working FIDDLE with this link 请通过此链接找到有效的FIDDLE

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

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