Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Javascript set button enable on checkbox true
Message
 
To
15/10/2010 07:40:00
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 4.0
Application:
Web
Miscellaneous
Thread ID:
01485567
Message ID:
01486317
Views:
44
>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
>

I'm not sure why you're existing code isn't working (could be something as simple as a typo in the JS), but I normally handle this kind of thing one of a few different ways (and you'll begin to appreciate why they added the ability to tell ASP.NET to not mess with the control ID's and to leave them as-is; it makes writing JS code way more complicated).

In almost every case I'll use jQuery for this, since it makes things easier.

In the simplest case I'll just add code into the page directly to do the binding (in your case you'd replace the code within the <$= %> tags with the real control names.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"</script

        <script type="text/javascript"
            $(document).ready(function () {
                $("#<%= this.chkAgree.ClientID %").click(function () {
                    var checked = $(this).attr('checked');
                    $("#<%= this.btnRun.ClientID %").attr('disabled', !checked);
                });
            });
        </script
If you need to add the code dynamically I'll usually just drop a literal control on the page and set its .Text property to the JS string, or if you need to do this from a user control I'd use Page.ClientScript.RegisterStartupScript() (or one of its variants). In every case you need to grab the ClientID of the control.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform