473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Sep 8 '08 #1
3 1689
DrBunchman
979 Expert 512MB
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.
Sep 9 '08 #2
Thanks a lot that worked.

Ayush.
Sep 9 '08 #3
DrBunchman
979 Expert 512MB
No problem, glad you got it working.

Dr B
Sep 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Kennedy | last post by:
I am writing the value from a textarea input box to a cookie. Long story but when I return to the page I want to pull the value from the cookie and put it back in the textbox. When I do this all...
1
by: Andrew Poulos | last post by:
I've written some ASP using javascript (rather than vbscript) and it runs as expected on my test IIS server. Recently a colleague said that he was unsure if an Apache server, that's setup to serve...
4
by: KK | last post by:
Hi, Does anybody know how to call server side function in javascript? Suppose I've a method named Test() at code behind of ASP.Net page. How can I call that method in javascript function ???...
5
by: Anon | last post by:
Since installing the security update http://www.microsoft.com/downloads/details.aspx?familyid=16DD21A1-C4EE-4ECA-8B80-7BD1DFEFB4F8&displaylang=en on our Windows 2000 server (SP4) all ASP pages...
1
by: JimmyFo | last post by:
Hi, this is a bit complicated but maybe someone can help here. I have an ASP.Net 2.0 page with a JavaScript file selector. I did this because I wanted to be able to select multiple files at a time....
3
by: ashima515 | last post by:
Hi... M a newbe to asp.net. I am trying to use a javascript function in my asp.net page. The function works fine but for the second time. I have made a function that displays an alert box. but wen...
2
by: RevJPZ | last post by:
I have a JavaScript function that is opening a new ASP page in a window with specific parameters. I want to pass information from the first page to the second. I can easily simulate the "post"...
3
by: TheLymner | last post by:
I have, what I believe, is a rather simple question. However, I cannot find the answer anywhere on the web nor in any of the library of xml or javascript/asp books available. How do I pass and store...
2
by: ublow56 | last post by:
I am trying to create an ASP application using javascript. I found may ways to connect to Ms Access using VBScript, but I can't find any for the Javascript... Can someone help me??? I just need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.