?
Solved

Check Boxes / Radio Buttons Multipole Selections

Posted on 2000-02-22
10
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 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