mardi 24 mai 2016

Disable submit button if two textboxes have no value not working properly

I have two text-boxes and one button. I want that the button be disabled if one of the textboxes have no value. With this code the button is enabled if just one textbox has a value.

HTML

<asp:TextBox ID="TextBox2" runat="server" onblur = "Toggle()"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" onblur = "Toggle()"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" Enabled = "false" />

JavaScript

 function Toggle() {
        var txt1 = document.getElementById("<%=TextBox1.ClientID %>");
        var txt2 = document.getElementById("<%=TextBox2.ClientID %>");
        var btn = document.getElementById("<%=Button1.ClientID %>");
        if (txt1.value == "" && txt2.value == "") {
            btn.disabled = true;
        } else {
            btn.disabled = false;
        }
    }

Aucun commentaire:

Enregistrer un commentaire