Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Javascript set button enable on checkbox true
Message
 
À
20/10/2010 11:03:50
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
Application:
Web
Divers
Thread ID:
01485567
Message ID:
01486358
Vues:
30
>
>The next one I am trying to do is enabling a "Continue" button when all three of the userID, Password, and retype password textboxs have been filled out or validated client side. Basically I do not want them to continue until I have valid values in all three boxes and the two passwords match. How would you approach this? I am adding jQuery into this project now.

The easiest might be to hook into the lost focus event of the controls and do the validation there. If you want to display an error message (to let them know their passwords don't match) then you'll want to add something like a div section with the message and hide or show it selectively. Something like this:
        <script type="text/javascript"
            $(document).ready(function () {
                $("#<%= this.txtUsername.ClientID %").blur(validatePassword);
                $("#<%= this.txtPassword.ClientID %").blur(validatePassword);
                $("#<%= this.txtRetypePassword.ClientID %").blur(validatePassword);
            });

            function validatePassword() {
                var username = $("#<%= this.txtUsername.ClientID %").val();
                var password = $("#<%= this.txtPassword.ClientID %").val();
                var retype = $("#<%= this.txtRetypePassword.ClientID %").val();
                var empty = (username.length == 0) || (password.length == 0) || (retype.length == 0);

                var valid = !empty && (password == retype);

                if (!empty && !valid) {
                    $("#password").show();
                }
                else {
                    $("#password").hide();
                }

                $("#txtLogin").attr('disabled', !valid);               
            }
        </script

        <div id="password" style="display:none;"The entered passwords do not match.</div
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform