[RESOLVED] firing javascript on OnCheckChanged radiobutton event
I have some javascript that I'm trying to fire off when the checked status of a radiobutton is changed. its suppose to uncheck any checkboxes that are checked on my page. the checkboxes are named CheckBox1, CheckBox2, etc. Here is my javascript
Code:
<script type = "text/javascript">
function uncheckAll()
{
for (var j = 1; j <= 14; j++)
{
box = eval("document.Form1.CheckBox" + j);
if (box.checked == true) box.checked = false;
}
}
</script>
and here is my code in my html:
Code:
<asp:RadioButton id="OptionButton3" OnCheckedChanged="uncheckAll()" runat="server" Text="CONCENTRIC OR COMPRESSED" GroupName="CableType"></asp:RadioButton>
But when I load the page i get this error:
Compiler Error Message: BC30456: 'uncheckAll' is not a member of 'ASP._500_10_aspx'.
I'm coding in VS.net. Why can't it recognize it?
Thank you!
Re: firing javascript on OnCheckChanged radiobutton event
You cannot execute client side script by using a tag within a server side object.
Therefore, make the radio button like this:
<asp:RadioButton id="OptionButton3" runat="server" Text="CONCENTRIC OR COMPRESSED" GroupName="CableType"></asp:RadioButton>
Then, in the Page_Load event, do the following Response.Write:
Response.Write("<sc" + "ript lang=\"javascript\" for=\"" + OptionButton2.clientID + "\" event=\"OnCheckChanged\">uncheckAll()</sc" + "ript>");
Re: firing javascript on OnCheckChanged radiobutton event
Well I changed the OnCheckChanged event to OnClick (even though VS.NET doesn't like it and underlines it) and it worked perfectly.
Which is better?
Re: firing javascript on OnCheckChanged radiobutton event
OnClick working for you, provided it continues, is a fluke.
If it is, indeed, working, then ignore the underline and keep going.
For future reference, make sure the code above is easily accessable for you.
Re: firing javascript on OnCheckChanged radiobutton event
Thanks again! I'll be back soon with more questions I'm sure.
Thanks for eveything!