javascript:asp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayush patel
    New Member
    • Jul 2008
    • 63

    javascript:asp

    Hi,

    I have an application in which clicking on a checkbox should make rest of the checkboxes checked. its rather simple. I have never used Javascript before so i have no clue how to get through this.

    here's my code.

    this is the checkbox which on checked should make other check boxes checked.
    Code:
    <td >
    input <%If (Session("stateid") <> "") Then Response.Write("checked=""checked""") : Response.Write("")%> name="stateid" type="checkbox" class="body" id="stateid"   onclick="javascript:checkall(stateID);" value="checkbox" />
                            All States.
    </td>
    this is the code for other checkboxes(its in a loop)

    Code:
    <td                                  
     <input <%For x = 0 to Ubound(Session("preferenceID"),1)%><%If (cInt(Session("preferenceID")(x)) = cInt((StateDDL.Fields.Item("stateID").Value))) Then Response.Write("checked=""checked""") : Response.Write("")%><%Next%> name="stateID"  type="checkbox" id="stateID" value="<%=(StateDDL.Fields.Item("stateID").Value)%>" />
                                    <%=(StateDDL.Fields.Item("stateName").Value)%> </td>

    and here's my javascript(i'm not sure how perfect this is)

    Code:
    <script type="text/JavaScript">
    function checkall(stateID) 
     { 
     
    stateID.Checked=true;
    
    }
    
    </script>
    but this is doing nothing.please help.

    Ayush
    Last edited by DrBunchman; Sep 9 '08, 07:12 AM. Reason: Added [Code] Tags - Please use the '#' button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Ayush,

    Try using the following example to help you. The javascript function Check_All_Check Boxes loops through all the inputs in the specified span tag and checks them.
    Code:
    <script type="text/JavaScript">
    function Check_All_CheckBoxes()
    {
    var span = document.getElementById('spanCheckBoxes');
    var chk
    var chks= span.getElementsByTagName('input');
    for (var i=0, len=chks.length; i<len; i++)
       {
       chk= chks[i];
       chk.checked = 1;
       }
    }
    </script>
    
    <td >
    <input type="checkbox" onclick="Check_All_CheckBoxes();" value="checkbox">All States.</input>
    </td>
    
    <td>
       <span id='spanCheckBoxes'>
       <%
       For x = 0 to 10
          %>
          <input name="stateID"  type="checkbox" value="<%=x%>" ><%=x%></input>
          <%
       Next
       %>
       </span>
    </td>
    Do you see how this works? Let me know how you get on.

    Dr B

    PS Please remember to use code tags to surround your code blocks.

    Comment

    • ayush patel
      New Member
      • Jul 2008
      • 63

      #3
      Thanks a lot that worked.

      Ayush.

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        No problem, glad you got it working.

        Dr B

        Comment

        Working...