?
Solved

Check Boxes / Radio Buttons Multipole Selections

Posted on 2000-02-22
10
Medium Priority
?
203 Views
Last Modified: 2012-05-04
I would like to have a form where aa user can select multiple choices.  I can do this with checkboxes but I would like to have an "All Of The Above" which would deselect all of the checkboxes from above.

Example
[] Archive
[] Current Issue
[] Another Choice

[] All of the Above

The user could select archive and Another choice, but if he selected All of the above I would like the choices above that were selected to be deselected.  Is there a way to do this?


0
Comment
Question by:gretchen
  • 6
  • 2
  • 2
10 Comments
 
LVL 8

Expert Comment

by:xabi
ID: 2545575
Here goes the answer:

<html>
<head>
<title>Example</title>
<script language="javascript">
<!--
function select_one() {
 document.myform.ch_all.checked = false
}

function deselect_all() {
 for (var i = 0; i<document.myform.elements.length; i++) {
  sName = document.myform.elements[i].name
  if ((sName .indexOf('ch_') != -1) && (sName != "ch_all")) {
   document.myform.elements[i].checked = false
  }
 }        
}
//-->
</script>
</head>
<body>
<form name="myform">
<input type="checkbox" name="ch_archive" onClick="if (this.checked) select_one();">Archive<br>
<input type="checkbox" name="ch_current" onClick="if (this.checked) select_one();">Current<br>
<input type="checkbox" name="ch_another" onClick="if (this.checked) select_one();">Another Choice<br><br>
<input type="checkbox" name="ch_all" onClick="if (this.checked) deselect_all();">All of the abovee<br>
</form>
</body>
</html>


xabi
0
 
LVL 5

Expert Comment

by:nathans
ID: 2546034
That is Correct!!!
0
 
LVL 8

Expert Comment

by:xabi
ID: 2546144
Points? :)

xabi
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
xabi earned 80 total points
ID: 2546205
Here goes a better script:
------- 8< -------- 8< ---------
<html>
<head>
<title>Example</title>
<script language="javascript">
<!--
function deselect_all(idform) {
 for (var i = 0; i<idform.elements.length; i++) {
  sName = idform.elements[i].name
  if ((sName.indexOf('ch_') != -1) && (sName != "ch_all")) {
   idform.elements[i].checked = false
  }
 }        
}
//-->
</script>
</head>
<body>
 <form name="myform">
  <input type="checkbox" name="ch_archive" onClick="if (this.checked) this.form.ch_all.checked = false;">Archive<br>
  <input type="checkbox" name="ch_current" onClick="if (this.checked) this.form.ch_all.checked = false;">Current<br>
  <input type="checkbox" name="ch_another" onClick="if (this.checked) this.form.ch_all.checked = false;">Another Choice<br><br>
  <input type="checkbox" name="ch_all"     onClick="if (this.checked) deselect_all(this.form);">All of the above<br>
 </form>
</body>
</html>
----------- 8< ------- 8< --------
xabi
0
 
LVL 5

Expert Comment

by:nathans
ID: 2546278
Hey, While your on a roll can you make a box to select ALL?
0
 
LVL 8

Expert Comment

by:xabi
ID: 2546437
Here goes the code for that:

-------- 8< --------- 8< -------
<html>
<head>
<title>Example</title>
<script language="javascript">
<!--
function deselect_all(idform, boxname, new_state) {
 for (var i = 0; i<idform.elements.length; i++) {
  sName = idform.elements[i].name
  if (sName.indexOf('ch_') != -1) {
   idform.elements[i].checked = new_state
  } else {
   if ((sName.indexOf('ch') != -1) && (sName != boxname)) {
    idform.elements[i].checked = false
   }
  }
 }        
}
function unmark_all(idform) {
 idform.chm_all.checked = false
 idform.chu_all.checked = false
}
//-->
</script>
</head>
<body>
 <form name="myform">
  <input type="checkbox" name="ch_archive" onClick="unmark_all(this.form);">Archive<br>
  <input type="checkbox" name="ch_current" onClick="unmark_all(this.form);">Current<br>
  <input type="checkbox" name="ch_another" onClick="unmark_all(this.form);">Another Choice<br><br>
  <input type="checkbox" name="chm_all"   onClick="if (this.checked) deselect_all(this.form, this.name, true);">Mark all<br>
  <input type="checkbox" name="chu_all"   onClick="if (this.checked) deselect_all(this.form, this.name, false);">Unmark all<br>
 </form>
</body>
</html>
----------- 8< --------- 8< -----

I'm so busy, so I will not change anything more today.

xabi
0
 
LVL 8

Expert Comment

by:xabi
ID: 2546440
And just for 20 points :) ...
0
 

Author Comment

by:gretchen
ID: 2548611
Thank You very much
gl
0
 

Author Comment

by:gretchen
ID: 2548637
Quick Question:  Can you recommened a book or website that talks about how to deal with the elements of checkboxes, forms, radio buttons, and the document object.  Things of this nature.  Anything would help.

gl
\
0
 
LVL 8

Expert Comment

by:xabi
ID: 2549509
yep:

For fomrs:
http://developer.irt.org/script/script.htm

and for anyother thing:
http://www.irt.org

xabi
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question