Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    55
    Thanks
    26
    Thanked 0 Times in 0 Posts

    change a checkbox if another checkbox is checked

    I'm new to coding, but I'm getting through every problem I've encountered thanks to the people here and on other forums.

    Now I'm wondering:

    - I have to 2 different arrays of check boxes (150 boxes each)
    - when a user clicks a card-shuffle button, it builds a deck based on the status of array #2
    - checkbox #1 in array #1 corrosponds to checkbox #1 in array #2.

    I need a statement that says " if checkbox #1 in array #1 ISN'T checked, then uncheck checkbox #1 in array #2."

    And so on and so forth for the next checkboxes in the arrays.

    Is this possible?

    Here's what I've been trying: (maybe I'm accessing the form elements incorrectly? I don't get any errors from this code, but it doesn't work)

    Code:
    function unflip_cards(){
    
    if (form.item_1_array_1.checked == true)
    	form.item_1_array_2.checked == true;
    
    if (form.item_2_array_1.checked == true)
    	form.item_2_array_2.checked == true;
    
    if (form.item_3_array_1.checked == true)
    	form.item_3_array_2.checked == true;
    
    if (form.item_4_array_1.checked == true)
    	form.item_4_array_2.checked == true;
    
    if (form.item_5_array_1.checked == true)
    	form.item_5_array_2.checked == true;
    
    if (form.item_6_array_1.checked == true)
    	form.item_6_array_2.checked == true;
    
    if (form.item_7_array_1.checked == true)
    	form.item_7_array_2.checked == true;
    
    if (form.item_8_array_1.checked == true)
    	form.item_8_array_2.checked == true;
    
    }

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    I need a statement that says " if checkbox #1 in array #1 ISN'T checked, then uncheck checkbox #1 in array #2."
    The syntax would be:
    Code:
    if ( !form.item_1_array_1.checked )
      form.item_1_array_2.checked = false;
    To do it for all elements:
    Code:
    for( var i = 1, elem; ( elem = form[ "item_" + i +"_array_1" ] ); i++ )
      if( !elem.checked )
        form[ "item_" + i +"_array_2" ].checked = false;
    That relies on all elements being numbered contiguously.

  • Users who have thanked Logic Ali for this post:

    Mindphaser (10-22-2012)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    55
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Thanks Logic Ali, I was actually able to figure it all out before I came back on the forum here and saw your solution.

    Exactly what I did and needed.

    Sorry a newbie such as myself had to post a question with such easy and obvious solutions. My coding skills leave lots to be desired. I'm getting better, but all my strengths are with the artistic side of web design.

    Thanks again LA, if I never figureded it out, this would have helped me


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •