0

I have two fields where the user can only write in one or the other, we validate the client side using the javascript below. The problem that I have is that the textboxes by default have a clear 'x' that when used doesn't trigger the javascript leaving one of the fields disabled.

How can I call the javascript function when the user clicks the clear 'x' of the textbox in order to get both fields enabled?

enter image description here

<asp:TextBox ID="txtFIELD1Val" runat="server" onKeyup="javascript:clearFields();" TabIndex="1" CssClass="cssTextbox"></asp:TextBox>

<asp:TextBox ID="txtFIELD2Val" runat="server" onKeyup="javascript:clearFields();" TabIndex="2" CssClass="cssTextbox"></asp:TextBox>

    function clearFields() {
        var txtFIELD1 = document.getElementById('<%= txtFIELD1Val.ClientID %>');
        var txtFIELD2 = document.getElementById('<%= txtFIELD2Val.ClientID %>');

        //Enable/Disable FIELD1 and FIELD2 fields based on text.
        if (txtFIELD1.value == "" && txtFIELD2.value == "") {
            txtFIELD1.disabled = false;
            txtFIELD2.disabled = false;
        }
        else if (txtFIELD1.value == "" || txtFIELD2.value != "") {
            txtFIELD1.disabled = true;
            txtFIELD2.disabled = false;
        }
        else if (txtFIELD1.value != "" || txtFIELD2.value == "") {
            txtFIELD1.disabled = false;
            txtFIELD2.disabled = true;
        }
    }
Edgar J. Rodriguez
  • 265
  • 1
  • 2
  • 13

1 Answers1

1

Remove IE10's "clear field" X button on certain inputs?

See the second answer, seems to be the best approach to getting rid of the 'X' and the problems it's causing.

Community
  • 1
  • 1
Nicholas Hirras
  • 2,560
  • 2
  • 20
  • 27
  • The problem is that the users community see the clear 'x' as a feature and removing features is not allowed unless requested and communicated. I had a discussion over issue but removing the button is out of the table as of this point. – Edgar J. Rodriguez Jan 19 '17 at 14:34
  • Can you remove the 'native' clear button and add your own that works the same in all browsers? – Nicholas Hirras Jan 19 '17 at 14:35
  • Yeah, its possible I can get away with that one. I agree it would be a simple approach to deal with the issue. I got caught up trying to fix the problem instead of looking for a work around. I'll make the suggestion. Thanks! – Edgar J. Rodriguez Jan 19 '17 at 14:39