Link to home
Start Free TrialLog in
Avatar of sharpnet
sharpnet

asked on

Error in a simple javascript call from a checkbox 'OnCheckedChange'

Morning,

I have been banging my head trying to figure out why a simple javascript call from a checkbox keeps failing.  The error comes back saying : CS1026 expected ), but the syntax is correct.  Below is my code.  The error occurs on the second line, the asp checkbox control.  Please help...

I've already tried removing the 'return' statement and modifying the syntax, but it should be fine the way it is...

Thanks,
Nick

******************************************************
Code:

<HeaderTemplate>
     <asp:CheckBox ID="cbxACHAll" OnCheckedChanged="javascript: return select_deselectAll(this.checked, this.id);" runat="server"></asp:CheckBox>
</HeaderTemplate>

Avatar of praneetha
praneetha

<asp:TemplateColumn HeaderText="View">
            <HeaderTemplate></HeaderTemplate>

is it in template column

"javascript: return select_deselectAll(this.checked, this.id);"

post the javascript code too...

Avatar of sharpnet

ASKER

Yeah, it's already in a template column:

Segment:
<asp:TemplateColumn>
      <HeaderTemplate>
            <asp:CheckBox ID="cbxACHAll" OnCheckedChanged="javascript: 'return select_deselectAll(this.checked, this.id)';" runat="server"></asp:CheckBox>
      </HeaderTemplate>
      <ItemTemplate>
            <asp:CheckBox ID="cbxACH" OnCheckedChanged="javascript: return select_deselectAll(this.checked, this.id);" runat="server"></asp:CheckBox>
      </ItemTemplate>
</asp:TemplateColumn>

Javascript:
function select_deselectAll(chkVal, idVal)
      {
            var frm = document.forms[0];
            // Loop through all elements
            for (i=0; i<frm.length; i++)
            {
                  // Look for our Header Template's Checkbox
                  if (idVal.indexOf('CheckAll') != -1)
                  {
                        // Check if main checkbox is checked, then select or deselect datagrid checkboxes
                        if(chkVal == true)
                        {
                              frm.elements[i].checked = true;
                        }
                        else
                        {
                              frm.elements[i].checked = false;
                        }
                        // Work here with the Item Template's multiple checkboxes
                  }
                  else if (idVal.indexOf('DeleteThis') != -1)
                  {
                        // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                        if(frm.elements[i].checked == false)
                        {
                              frm.elements[1].checked = false; //Uncheck main select all checkbox
                        }
                  }
            }
<asp:CheckBox ID="cbxACHAll" OnCheckedChanged=

i guee onClick is the rightevent not OnCheckChanged
Visual Studio.NET doesn't recognize an onClick event, just an OnCheckedChanged...
for checkboxes that is...
ASKER CERTIFIED SOLUTION
Avatar of praneetha
praneetha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SON OF A....

That drives me nuts... It works now, changing those OnCheckedChanged to onClick.  I suppose Microsoft doesn't recognize the problem, either, since MSDN doesn't have any info on it.

Well, thanks for that.  I'll keep that tidbit in my quiver for some time to come.

Nick