Checking One Box when I check a second checkbox

R

Rich

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("")%>>
 
L

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.checked"
 
L

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.checked==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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top