[Javascript] Checkbox Focus

Peter Brunone peter at brunone.com
Wed Jan 22 21:53:16 CST 2003


	Okay, without a clear picture (my mind is a bit muddled lately; something
about being a relatively new father with a teething baby), this is my best
shot:

<input type="checkbox" name="whatever" value="1,2,3,yadda,yadda,yadda"
onClick="checkChoice(theFieldName, 9999, this.value);">

	Now I'm not sure if the braces below totally match up, but the important
part is what I've put in the else if(i==9999) { } section.

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkChoice1(field, i, theValue) {
  if (i == 0) { // "All" checkbox selected.
    if (field[0].checked == true) {
      for (i = 1; i < field.length; i++)
      field[i].checked = false;
      }
    }

  else if(i==9999) {
  // Because 9999 seems unlikely to be used otherwise
      for (i = 0; i < field.length; i++) {
        if(field[i].value != theValue) {
          field[i].checked = false;
          }
        }
	}

  else { // A checkbox other than "Any" selected.
    if (field[i].checked == true) {
      field[0].checked = false;
      }
    }
  }
// End -->
</SCRIPT>

	This may not be entirely correct, but hopefully it gives you an idea of how
to address the issue.  Feel free to pepper us with more questions if you so
choose.

Cheers,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of David Hannum
|Sent: Wednesday, January 22, 2003 11:48 AM
|To: javascript at LaTech.edu
|Subject: Re: [Javascript] Checkbox Focus
|
|
|Peter,
|
|Here's what I'm using to clear the "two group" method currently.
|Because I'm using the form to do a dynamic query on the other end, I
|need (want may be the case) the names to all be the same. That gives
|me a nice, tight, comma delimited list on the other end to work with.
|
|This code is not original. Someone helped me with it. Can a third
|group be added?
|
|<SCRIPT LANGUAGE="JavaScript">
|<!-- Begin
|function checkChoice1(field, i) {
|if (i == 0) { // "All" checkbox selected.
|if (field[0].checked == true) {
|for (i = 1; i < field.length; i++)
|field[i].checked = false;
|}
|}
|else { // A checkbox other than "Any" selected.
|if (field[i].checked == true) {
|field[0].checked = false;
|}
|}
|}
|// End -->
|</SCRIPT>
|
|
|----- Original Message -----
|From: "Peter Brunone" <peter at brunone.com>
|To: <javascript at LaTech.edu>
|Sent: Wednesday, January 22, 2003 11:57 AM
|Subject: Re: [Javascript] Checkbox Focus
|
|
|Dave,
|
|   I'm still a little confused.  Could you perhaps illustrate with some
|source code so we have a starting point?
|
|Cheers,
|
|Peter
|
|---------- Original Message ----------------------------------
|From: "David Hannum" <hannum at ohio.edu>
|Reply-To: javascript at LaTech.edu
|Date: Wed, 22 Jan 2003 09:51:30 -0500
|
|>Here's an interesting one.  I'm generating a list of checkboxes
|dynamically.
|>Now, the catcher is this.  While all of the checkboxes have the same name,
|>they are divided into three groups.  The first group is one box which has
|>the value equal to a comma delimited list of all the other checkbox values
|>in the the first and second groups.  The second group is a separate
|checkbox
|>for each of the values found in the first group.  The third group is one
|box
|>with a comma delimited list of separate values.  Now, here is what I need.
|>A)  If the user clicks the group one box, I need all boxes in groups two
|and
|>three to clear.
|>B)  If the user clicks any box or boxes in group two, I need the group one
|>box and the group three box to clear.
|>C)  If the user clicks the group three box, I need all boxes in group one
|>and two to clear.
|>
|>I have it working for group one and two.  But incorporating the third
|option
|>is out of my league.  Any help would be greatly appreciated.
|>
|>Kind Regards,
|>Dave Hannum




More information about the Javascript mailing list