473,388 Members | 1,322 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,388 software developers and data experts.

javascript checkall not working

I am trying to get a checkall/uncheckall working for my form with javascript on an apache web server. I know I am doing something wrong and can not get the proper syntax for the javascript to work.

thanks for the help.


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script LANGUAGE="JavaScript">
  4. function doIt(v)
  5. {
  6.  
  7. document.f1.c3.checked=false;
  8. document.f1.c4.checked=false;
  9.  
  10. document.f1.seq23923.checked=val(v);
  11. document.f1.seq23925.checked=val(v);
  12. document.f1.seq23938.checked=val(v);
  13. }
  14. </script>
  15. </head>
  16.  
  17. <body>
  18.  
  19. <Form name=f1 >
  20.  
  21. <input type="checkbox" name="c3" value="false" onclick="doIt(this.value)">All Not Checked<BR>
  22. <input type="checkbox" name="c4" value="true" onclick="doIt(this.value)">All Checked<BR>
  23. <hr>
  24. <input type="checkbox" name="seq" value="23923">23923<br>
  25. <input type="checkbox" name="seq" value="23925">23925<br>
  26. <input type="checkbox" name="seq" value="23938">23938<br>
  27.  
  28.  
  29. </form>
  30.  
  31. </body>
  32. </html>
  33.  
Nov 24 '06 #1
4 1878
Here you're passing variable "v" to function Val() which doesn't exist in the script.

Expand|Select|Wrap|Line Numbers
  1. document.f1.seq23923.checked=val(v);
  2. document.f1.seq23925.checked=val(v);
  3. document.f1.seq23938.checked=val(v);
  4.  
I'm not sure what the script is supposed to do when it works properly. Could you provide more information?
Nov 24 '06 #2
I am trying the get my checkbox to be checked or unchecked the checkbox name 'seq'. I am not careing about the named checkedboxes c3, or c4.
Nov 24 '06 #3
This should be close to what you're looking for:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7. <script type="text/javascript">
  8. function uncheck()
  9. {
  10.     // the elements whose names are "seq" are stored in an array
  11.     var seqArray = document.getElementsByName("seq");
  12.  
  13.     // if the elements exist
  14.     if(seqArray)
  15.     {
  16.         // loop through the elements sequentially
  17.         for(var i = 0; i < seqArray.length; i++)
  18.         {
  19.             // if the particular box is checked, uncheck it
  20.             if(seqArray[i].checked == true)
  21.             {
  22.                 seqArray[i].checked = false;
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. function check()
  29. {
  30.     var seqArray = document.getElementsByName("seq");
  31.  
  32.     if(seqArray)
  33.     {
  34.         for(var i = 0; i < seqArray.length; i++)
  35.         {
  36.             if(seqArray[i].checked == false)
  37.             {
  38.                 seqArray[i].checked = true;
  39.             }
  40.         }
  41.     }
  42. }
  43. </script>
  44. <title>Untitled Document</title>
  45. </head>
  46.  
  47. <body>
  48.  
  49. <form name="f1">
  50. <input type="checkbox" name="c3" onclick="uncheck()">All Not Checked<BR>
  51. <input type="checkbox" name="c4" checked="checked" onclick="check()">All Checked<br />
  52. <hr />
  53. <input type="checkbox" name="seq" checked="checked" value="23923">23923<br>
  54. <input type="checkbox" name="seq" checked="checked" value="23925">23925<br>
  55. <input type="checkbox" name="seq" checked="checked" value="23938">23938<br>
  56. </form>
  57.  
  58. </body>
  59. </html>
  60.  
  61.  
One thing to note is that to make a checkbox checked by default, use check="checked" within the input element.

There's no need to pass the All Not Checked and All Checked input elements because you're not testing for them. Just get what you want to modify, not what's doing the modifying.

You also might consider making the All Not Checked and All Checked boxes radio buttons, since it only makes since for only one to be checked at a time.

Good luck!
Nov 25 '06 #4
WOW! I was wondering why everybody was put loops for the checkall stuff. I though I did not want a loop, because my values for the checkboxes where large and getting larger. I did an alert to look at some of the variables and then it clicked.


Thanks,
Nov 25 '06 #5

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

Similar topics

1
by: walkerhunter | last post by:
I have the three embedded Ruby(erb) check_boxes below: Patient #1<%= check_box("patient", '1', {}, "yes","no") %></br> Patient #2<%= check_box("patient", '2', {}, "yes","no") %></br> Patient...
5
by: chadlupkes | last post by:
I'm working with an internal website with a form with a bunch of checkboxes indicating records that I need to work with. Part of my job is printing all those records, meaning I need to check each...
4
by: 159789 | last post by:
Hi, I am new to javascript. I want to select all the checkboxes or deselect all in a form, based on the state of one checkbox. Here is the code: <html> <script language="JavaScript">...
3
by: chinki | last post by:
I'm facing a problem in form related to employee Leave which has two asp controls with calendar image which is built in javascript as, <asp:textbox id="txtlsdate" runat="server"...
4
by: Mike P | last post by:
I am trying to add check all functionality to my grid view, but I can't get it to work. Here is my gridview : <asp:TemplateField> <ItemTemplate> <asp:CheckBox runat="server"...
4
by: gsaray101 | last post by:
I have an asp.net page that has one radiolist (called lstcheck) and one checkboxlist (call lstExchange). Depending on the which radiolist item is checked, I need to clear the checkbox list or check...
5
by: Muffinthief | last post by:
Hi guys, what I'm trying to do is very simple. Just make a simple check/uncheck button for some checkboxes. Here's what I have. <script language="JavaScript"> function checkAll(field) { for...
3
by: ayush patel | last post by:
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...
1
by: lolcat | last post by:
Hi guys, new here and to javascript, I have this form that I am trying to you javascript to validate the multiple input text boxes. form as follows <form action="login.php" method="post"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.