Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 8th, 2008, 03:43 PM
Member
 
Join Date: Jul 2008
Posts: 63
Default 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.
Expand|Select|Wrap|Line Numbers
  1. <td >
  2. 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" />
  3.                         All States.
  4. </td>
this is the code for other checkboxes(its in a loop)

Expand|Select|Wrap|Line Numbers
  1. <td                                  
  2.  <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)%>" />
  3.                                 <%=(StateDDL.Fields.Item("stateName").Value)%> </td>

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

Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. function checkall(stateID) 
  3.  { 
  4.  
  5. stateID.Checked=true;
  6.  
  7. }
  8.  
  9. </script>
but this is doing nothing.please help.

Ayush

Last edited by DrBunchman; September 9th, 2008 at 08:12 AM. Reason: Added [Code] Tags - Please use the '#' button
Reply
  #2  
Old September 9th, 2008, 08:37 AM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 926
Default

Hi Ayush,

Try using the following example to help you. The javascript function Check_All_CheckBoxes loops through all the inputs in the specified span tag and checks them.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. function Check_All_CheckBoxes()
  3. {
  4. var span = document.getElementById('spanCheckBoxes');
  5. var chk
  6. var chks= span.getElementsByTagName('input');
  7. for (var i=0, len=chks.length; i<len; i++)
  8.    {
  9.    chk= chks[i];
  10.    chk.checked = 1;
  11.    }
  12. }
  13. </script>
  14.  
  15. <td >
  16. <input type="checkbox" onclick="Check_All_CheckBoxes();" value="checkbox">All States.</input>
  17. </td>
  18.  
  19. <td>
  20.    <span id='spanCheckBoxes'>
  21.    <%
  22.    For x = 0 to 10
  23.       %>
  24.       <input name="stateID"  type="checkbox" value="<%=x%>" ><%=x%></input>
  25.       <%
  26.    Next
  27.    %>
  28.    </span>
  29. </td>
  30.  
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.
Reply
  #3  
Old September 9th, 2008, 06:00 PM
Member
 
Join Date: Jul 2008
Posts: 63
Default

Thanks a lot that worked.

Ayush.
Reply
  #4  
Old September 10th, 2008, 03:47 PM
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 926
Default

No problem, glad you got it working.

Dr B
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 204,874 network members.