Solved

Check Boxes / Radio Buttons Multipole Selections

Posted on 2000-02-22
10
159 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
Comment Utility
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
Comment Utility
That is Correct!!!
0
 
LVL 8

Expert Comment

by:xabi
Comment Utility
Points? :)

xabi
0
 
LVL 8

Accepted Solution

by:
xabi earned 20 total points
Comment Utility
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
Comment Utility
Hey, While your on a roll can you make a box to select ALL?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:xabi
Comment Utility
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
Comment Utility
And just for 20 points :) ...
0
 

Author Comment

by:gretchen
Comment Utility
Thank You very much
gl
0
 

Author Comment

by:gretchen
Comment Utility
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
Comment Utility
yep:

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

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

xabi
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now