bizzydint Posted May 5, 2005 Posted May 5, 2005 I'm attempting to have a bit of javascript that counts how many checkboxes are ticked and displays a simple alert when the user goes over the specified maximum. That part is simple. It gets slightly more complicated in that there are several lists of items with different maximums on each list (eg select 2 items from List A and select 5 items from List B etc). So the javascript simply calls the functions with "CountChecked(this, maxCountAllowed, GroupID)" and it works out what it's doing. Still simple. The problem is that all the data comes from a database and is completely variable. The asp.net checkbox control is letting me have a "onClick" command (although it's grumbling that it doesnt support it but it lets it through anyway) - but I cant seem to put variables in there... This works fine: <asp:CheckBox ID="cbx" onClick='CountChecks(this, 3, 1)' Runat=server> </asp:CheckBox> But not this: <asp:CheckBox ID="cbx" onClick='CountChecked(this, 3, <%#groupID %>)' Runat=server ></asp:CheckBox> It doesnt error - it simply writes "<% # groupID %>" onto the HTML instead of working out what the value of groupID is and putting that in. It's all databound etc. Am I missing something obvious? Quote Grant me the serenity to accept the things I cannot change, the courage to change the things I cannot accept and the wisdom to hide the bodies of those people I had to kill today cos they pi**ed me off.
Mister E Posted May 5, 2005 Posted May 5, 2005 Just use the Attributes collection:CheckBox1.Attributes.Add("onClick","CountChecked(this, 3, " + groupID + ")");If you check out the generated HTML on the client side you will see that this accomplishes what you need. Quote
bizzydint Posted May 6, 2005 Author Posted May 6, 2005 Thanks! So obvious - cant believe I forgot about that one.... Quote Grant me the serenity to accept the things I cannot change, the courage to change the things I cannot accept and the wisdom to hide the bodies of those people I had to kill today cos they pi**ed me off.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.