Solved

Check Boxes / Radio Buttons Multipole Selections

Posted on 2000-02-22
10
193 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
Technology Partners: 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 20 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

Suggested Solutions

Title # Comments Views Activity
Navigation Menu Does Not Show on iPad 4 59
Text too large in Chrome 17 83
HTML auto refresh to another site 4 45
Checkbox changes display when resizing window 8 26
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.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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