Checking One Box when I check a second checkbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rich

    Checking One Box when I check a second checkbox

    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="docume nt.form2.BCPCon tact.checked=tr ue" 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_e ditAction%>" name="form1">


    <input name="StandardC ontact" type="checkbox" value=1 <%If
    (CStr(rsUsers.F ields.Item("Sta ndardContact"). Value) = CStr("True"))
    Then Response.Write( "checked") : Response.Write( "")%>>
    <input type="hidden" name="MM_update " value="form1">
    <input type="hidden" name="MM_record Id" value="<%=
    rsUsers.Fields. Item("UserId"). Value %>">



    <input type="checkbox" name="PrimaryCo ntact" value=1 <%If
    (CStr(rsUsers.F ields.Item("Pri mary").Value) = CStr("True")) Then
    Response.Write( "checked") : Response.Write( "")%>>
  • Lee

    #2
    Re: Checking One Box when I check a second checkbox

    Rich said:
    [color=blue]
    >How can I modify this form to check the Standard contact button when I
    >check the primary box?[/color]

    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.f orm.StandardCon tact.checked|=t his.checked"

    Comment

    • Woody

      #3
      Re: Checking One Box when I check a second checkbox

      This worked great great I used

      <input type="checkbox" name="PrimaryCo ntact"
      onclick="this.f orm.StandardCon tact.checked|=t his.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="StandardC ontact"
      onclick="this.f orm.PrimaryCont act.checked|=th is.checked==fal se" >

      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="StandardC ontact"
      onclick="this.f orm.PrimaryCont act.checked==fa lse|=this.check ed==false" >
      and
      <input type="checkbox" name="StandardC ontact"
      onclick="this.f orm.PrimaryCont act.unchecked|= this.checked==f alse" >

      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" <REM0VElbspamtr ap@cox.net> wrote in message
      news:c8d73u0k6v @drn.newsguy.co m...[color=blue]
      > Rich said:
      >[color=green]
      > >How can I modify this form to check the Standard contact button when I
      > >check the primary box?[/color]
      >
      > 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.f orm.StandardCon tact.checked|=t his.checked"
      >[/color]


      Comment

      • Lee

        #4
        Re: Checking One Box when I check a second checkbox

        Woody said:[color=blue]
        >
        >This worked great great I used
        >
        > <input type="checkbox" name="PrimaryCo ntact"
        >onclick="this. form.StandardCo ntact.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="StandardC ontact"
        >onclick="this. form.PrimaryCon tact.checked|=t his.checked==fa lse" >
        >
        >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="StandardC ontact"
        >onclick="this. form.PrimaryCon tact.checked==f alse|=this.chec ked==false" >
        >and
        ><input type="checkbox" name="StandardC ontact"
        >onclick="this. form.PrimaryCon tact.unchecked| =this.checked== false" >
        >
        >However no matter what I do I cant modify the first part so that the
        >PrimaryConta ct state is set to unchecked when the standard is unchecked. Is
        >that modifiction possible with the code I was given?[/color]

        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="StandardC ontact"[color=blue]
        >onclick="if(!t his.checked)thi s.form.PrimaryC ontact.checked= false">[/color]

        Comment

        Working...