Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Javascript set button enable on checkbox true
Message
From
20/10/2010 11:03:50
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:
01486318
Views:
29
>>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.

Hi Paul,

Interestingly I have used jQuery before but it has been awhile so I was just reviewing a video on this as I got your message. I have the script working now as javascript but I have some others I need to do and was struggling with those also. Because my script needs to execute in a Web User control I am using the Page.ClientScript.RegisterClientScriptBlock() method and it is working. The client Id values are ugly and was causing me the problem. Viv did help with some code to help match it to another.

I also found a property on my control that is "ClientIDMode" and the values are Inherit, AutoID, Predictable, and Static. This is a telerik control so not sure as i just found this if it exist on other controls yet. The default seems to be set to AutoID so maybe changing this to static would be helpful in this matter.

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.
Thanks
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform