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

Check box select/unselect for boxes in a fieldset

Greetings,

I have an ASP page containing a Record Insertion Form with a number of fields linked to an Access database. Within this form, I have a fieldset with six checkboxes, one of which is a "Select ALL" checkbox that selects or unselects all checkboxes in the fieldset.

My problem is that when I select the "Select ALL" checkbox, it selects every checkbox in the form, not just those in the fieldset.

Here is the code for the "Select ALL" checkbox:

<td><input type="checkbox" name="PIC_RgnImpact_SelectALL" "value="1" onclick='RgnCheckedAll(form1);'/></td>

Here is the Javascript for the function:

<script language=javascript>

checked=false;
function RgnCheckedAll (form1) {
var aa= document.getElementById('form1');
if (checked == false)
{
checked = true
}
else
{
checked = false
}
for (var i =0; i < aa.elements.length; i++)
{
aa.elements[i].checked = checked;
}
}
</script>

I'm relatively new to Javascript and am unsure how to code the form to capture only the checkboxes in my fieldset.

Whatever advice anyone has would be much appreciated.

- JM
Apr 15 '08 #1
3 2976
pronerd
392 Expert 256MB
Hi,

Welcome to the forum. You may find you will get more responses if you use code tags when posting code. It is much harder to read posted code without them.


it selects every checkbox in the form, not just those in the fieldset.
I am not clear on what is meant by "fieldset". How are those check boxes differentiated? Since the loop goes though every field in the form it is going to effect all of them.

You could either start your loop from an element that surrounds this set of check boxes, or use specific values in one of the attributes that you can test in the loop.

Example :
[HTML]
<form>
<input type="checkbox" id="field1Set1" />
<input type="checkbox" id="field2Set1" />
<input type="checkbox" id="field3Set1" />
<input type="checkbox" id="field1Set2" />
<input type="checkbox" id="field2Set2" />
<input type="checkbox" id="field3Set2" />
<input type="checkbox" id="field1Set3" />
<input type="checkbox" id="field2Set3" />
<input type="checkbox" id="field3Set3" />
</form>

[/HTML]
Apr 17 '08 #2
Thanks for the suggestion about the code tags. I'd wondered how everyone posted their code in that way and I now know how to do it.

As for the fieldset, it is as a form element in the Dreamweaver CS3 software package that surrounds a set of checkboxes. Here's an example of my fieldset code (the checkboxes are in a table within the element):

Expand|Select|Wrap|Line Numbers
  1. <fieldset>
  2.             <legend>FedEx Regions</legend>
  3.             <table width="247">
  4.               <tr>
  5.                 <td width="22"><input type="checkbox" name="PIC_RgnImpact_US" value="1" /></td>
  6.                 <td width="82"><span class="style47">US</span></td>
  7.                 <td width="20"><input type="checkbox" name="PIC_RgnImpact_APAC" value="1" /></td>
  8.                 <td width="103"><span class="style47">APAC</span></td>
  9.               </tr>
  10.               <tr>
  11.                 <td><input type="checkbox" name="PIC_RgnImpact_CAN" value="1" /></td>
  12.                 <td><span class="style47">CAN</span></td>
  13.                 <td><input name="PIC_RgnImpact_LAC" type="checkbox" value="1" /></td>
  14.                 <td><span class="style47">LAC</span></td>
  15.               </tr>
  16.               <tr>
  17.                 <td><input type="checkbox" name="PIC_RgnImpact_EMEA" value="1" /></td>
  18.                 <td><span class="style47">EMEA</span></td>
  19.                 <td><input type="checkbox" name="PIC_RgnImpact_SelectALL" "value="1" onclick='RgnCheckedAll(form1);'/></td>
  20.                 <td><span class="style50">Select ALL</span></td>
  21.               </tr>
  22.             </table>
  23.             </fieldset>
Back to your example of giving each a specific value ID (e.g., id=field1set1), how do you suggest I incorporate that into my function? Here again is the function code (this time wrapped by CODE tags):

Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2.  
  3. checked=false;
  4. function RgnCheckedAll (form1) {
  5.     var aa= document.getElementById('form1');
  6.      if (checked == false)
  7.           {
  8.            checked = true
  9.           }
  10.         else
  11.           {
  12.           checked = false
  13.           }
  14.     for (var i =0; i < aa.elements.length; i++) 
  15.     {
  16.      aa.elements[i].checked = checked;
  17.     }
  18.       }
  19. </script>
Apr 17 '08 #3
pronerd
392 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2.  
  3. checked=false;
  4.     function RgnCheckedAll (form1, setName) {
  5.         var aa= document.getElementById('form1');
  6.         if (checked == false)  {
  7.             checked = true
  8.         } else {
  9.             checked = false
  10.         }
  11.  
  12.         for (var i =0; i < aa.elements.length; i++) {
  13.             var formElement = aa.elements[i];
  14.             if(formElement.indexOf(setName) > -1 ) {
  15.             aa.elements[i].checked = checked;
  16.             }
  17.     }
  18.       }
  19. </script>
Apr 17 '08 #4

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

Similar topics

2
by: Hi5 | last post by:
Hi, Is there any chance of getting to know how to make a drop down as a Multi select list boxes in Access? Many Thanks
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
1
by: theSquid | last post by:
I am trying to sort through data in one table using the criteria selected on a form in a few multi-select list boxes. Each list box would be used to sort a different field in the table. The...
14
by: Heggr | last post by:
I have a page that when you click on a button it is supposed to add 5 more rows to an existing table. This functionality works but then we had to change one of the cells from using a Text box to...
1
by: mishasoft | last post by:
Hi all, I have a HTML multiple select (ListBox) control: <select id="mySelect" multiple> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> ...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
2
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
2
by: azegurb | last post by:
hi i have created function that automatically adds rows with chekcboxes. i can create two button that one serves checking all checkboxes and the another one serves for unchecking rows. but i would...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.