Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-21-2012, 09:37 PM   PM User | #1
Mindphaser
New Coder

 
Join Date: Oct 2012
Posts: 55
Thanks: 26
Thanked 0 Times in 0 Posts
Mindphaser is an unknown quantity at this point
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;

}
Mindphaser is offline   Reply With Quote
Old 10-22-2012, 12:18 AM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
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.
Logic Ali is offline   Reply With Quote
Users who have thanked Logic Ali for this post:
Mindphaser (10-22-2012)
Old 10-22-2012, 06:08 PM   PM User | #3
Mindphaser
New Coder

 
Join Date: Oct 2012
Posts: 55
Thanks: 26
Thanked 0 Times in 0 Posts
Mindphaser is an unknown quantity at this point
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
Mindphaser is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:03 PM.


Advertisement
Log in to turn off these ads.