vendredi 22 septembre 2017

cannot disable a field unless using onClick="function" to do so

So here is an issues, I have a dropdown, a checkbox and a textbox. I let the user select a value from the drop down, however, if their selection is not there, then user can check the checkbox, in which case textbox is supposed to get ENABLED and they can type in their value. ALSO, if checkbox is check then, the selection in Dropdown goes to original value and is supposed to get disabled.

The problem I have is, when the page loads, my textbox is enabled. however, if I click the checkbox and unclick it - then textbox becomes disabled

In other words, the textbox is supposed to be disabled, if user checks the checkbox, then it should become enabled. However, if user wants to pick a selection from Drop then, in which case they would uncheck the checkbox, the textbox should then become disabled, and drop down enabled again.

<td width="305px">
   <asp:DropDownList ID="drpBHRAExchangeWithID" runat="server" Width="300px">
   </asp:DropDownList>

</td>
<td align="center" width="8%">
  <asp:CheckBox ID="chkBHRAExchangeOr" runat="server" onclick="ExchangeWithProvider(); " Text="OR" />
 </td>
 <td>
 <asp:TextBox ID="txtBHRAExchangeEntities" runat="server" MaxLength="250" Width="98%"></asp:TextBox>
 <asp:RequiredFieldValidator ID="rfvBHRAExchangeEntities" runat="server"                                                 
  ControlToValidate="txtBHRAExchangeEntities" Display="None" 
  ErrorMessage="Please select OR enter a response to '...to exchange with'" 
  ValidationGroup="save"> </asp:RequiredFieldValidator>
  </td>

JS for ExchangeWithProvider

function ExchangeWithProvider() {
    try {
        if (document.getElementById('<%=chkBHRAExchangeOr.ClientID %>').disabled == false) {
            if (document.getElementById('<%=chkBHRAExchangeOr.ClientID %>').checked == true) {
                document.getElementById('<%=drpBHRAExchangeWithID.ClientID %>').disabled = true;
                document.getElementById('<%=drpBHRAExchangeWithID.ClientID %>').value = "0"
                ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeWithID.ClientID %>'), false);

                document.getElementById('<%=txtBHRAExchangeEntities.ClientID %>').disabled = false;
                ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeEntities.ClientID %>'), true);
            }
            else {
                document.getElementById('<%=drpBHRAExchangeWithID.ClientID %>').disabled = false;
                ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeWithID.ClientID %>'), true);

                document.getElementById('<%=txtBHRAExchangeEntities.ClientID %>').disabled = true;
                document.getElementById('<%=txtBHRAExchangeEntities.ClientID %>').value = ""
                ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeEntities.ClientID %>'), false);
            }
        }
        else {
            ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeWithID.ClientID %>'), false);
            ValidatorEnable(document.getElementById('<%=rfvBHRAExchangeEntities.ClientID %>'), false);
        }




Aucun commentaire:

Enregistrer un commentaire