By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Checking One Box when I check a second checkbox

P: n/a
I have a form with 2 check boxes. One of the check boxes is used to
specify that the user is a "primary contact." When I check the
primary contact box I want a second box for "standard contact" to be
checked as all primary contacts must be standard contacts. If I
uncheck the primary contact no change in status of the standard
contact is needed. I am assuming I can use some onclick function but
I tried using a onclick on the one box to check the second. The code
I used onClick="document.form2.BCPContact.checked=true" I was hoping
this would check the second box anytime I clicked the first. I
realize this doesnt do exactly what I ask but I couldnt even get that
part working. Is there a problem in my syntax?

How can I modify this form to check the Standard contact button when I
check the primary box?
<form method="POST" action="<%=MM_editAction%>" name="form1">
<input name="StandardContact" type="checkbox" value=1 <%If
(CStr(rsUsers.Fields.Item("StandardContact").Value ) = CStr("True"))
Then Response.Write("checked") : Response.Write("")%>>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%=
rsUsers.Fields.Item("UserId").Value %>">

<input type="checkbox" name="PrimaryContact" value=1 <%If
(CStr(rsUsers.Fields.Item("Primary").Value) = CStr("True")) Then
Response.Write("checked") : Response.Write("")%>>
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
Rich said:
How can I modify this form to check the Standard contact button when I
check the primary box?


When the PrimaryContact checkbox is clicked, you want to
set the value of StandardContact.checked to be true if it
was already true, or if PrimaryContact is now checked.

Since the two controls are in the same form, you can refer
to the form that contains them both as "this.form".

So what you want is to set the onclick attribute of the
PrimaryContact checkbox to:

onclick="this.form.StandardContact.checked|=this.c hecked"

Jul 23 '05 #2

P: n/a
This worked great great I used

<input type="checkbox" name="PrimaryContact"
onclick="this.form.StandardContact.checked|=this.c hecked"

and it checks the StandardContact if I check the primary. I am trying to
create a second version of the script so that it unchecks the primary if I
uncheck the secondary.

The closested on got was:
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.checked|=this.ch ecked==false" >

This code checks the PrimaryContact box when I uncheck the StandardContact
Box. The problem is that I want to uncheck. I tried modifying the code to
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.checked==false|= this.checked==false" >
and
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.unchecked|=this. checked==false" >

However no matter what I do I cant modify the first part so that the
PrimaryContact state is set to unchecked when the standard is unchecked. Is
that modifiction possible with the code I was given?


"Lee" <RE**************@cox.net> wrote in message
news:c8********@drn.newsguy.com...
Rich said:
How can I modify this form to check the Standard contact button when I
check the primary box?


When the PrimaryContact checkbox is clicked, you want to
set the value of StandardContact.checked to be true if it
was already true, or if PrimaryContact is now checked.

Since the two controls are in the same form, you can refer
to the form that contains them both as "this.form".

So what you want is to set the onclick attribute of the
PrimaryContact checkbox to:

onclick="this.form.StandardContact.checked|=this.c hecked"

Jul 23 '05 #3

P: n/a
Lee
Woody said:

This worked great great I used

<input type="checkbox" name="PrimaryContact"
onclick="this.form.StandardContact.checked|=this. checked"

and it checks the StandardContact if I check the primary. I am trying to
create a second version of the script so that it unchecks the primary if I
uncheck the secondary.

The closested on got was:
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.checked|=this.c hecked==false" >

This code checks the PrimaryContact box when I uncheck the StandardContact
Box. The problem is that I want to uncheck. I tried modifying the code to
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.checked==false| =this.checked==false" >
and
<input type="checkbox" name="StandardContact"
onclick="this.form.PrimaryContact.unchecked|=this .checked==false" >

However no matter what I do I cant modify the first part so that the
PrimaryContact state is set to unchecked when the standard is unchecked. Is
that modifiction possible with the code I was given?
You need a slightly more complicated form for that case.
You don't use |= because the new state of PrimaryContact
doesn't depend on its previous state. You don't want to
change the state at all unless this.checked is false, and
in that case, you always want to set StandardContact to
be unchecked:

<input type="checkbox" name="StandardContact"onclick="if(!this.checked)this.form.PrimaryContac t.checked=false">


Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.