Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Javascript set button enable on checkbox true
Message
De
15/10/2010 07:40:00
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Javascript set button enable on checkbox true
Versions des environnements
Environment:
C# 4.0
Application:
Web
Divers
Thread ID:
01485567
Message ID:
01485567
Vues:
131
Hi all,

I have what I thought would be a simple task. I have a user control on an asp.net page showing an agreement form. All I want to do is enable a continue button after a checkbox is checked to indicate agreement. I wanted to avoid a postback so am trying to set the button to enabled when the checkbox is checked but I cannot get this to work. I have tried several approaches found on web including the below. (I changed the angle brackets to parens so they would show)

Anybody with javascript knowledge have an answer that might help me? Thanks a bunch
Tim
This is just one approach I tried.

     (mm:mmCheckBox ID="chkAgree" runat="server" Checked="false" Text="I Agree to the Terms" /)
             
     (mm:mmButton ID="btnAgreeContinue" runat="server" Text="Continue" 
                Enabled="False" /)
     
function SetAgreeAndContinue(checkbox, buttonid) {
        var button = document.getElementById(buttonid);

        if (checkbox.checked)
            button.enabled = true;
        else
            button.enabled = false;
    }

In the code behind
protected override void OnInit(EventArgs e)
{
     chkAgree.Attributes.Add("onClick", string.Format("javascript:SetAgreeAndContinue(this,'{0}');", btnAgreeContinue.ClientID));
     base.OnInit(e);
}
Timothy Bryan
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform