JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 21st, 2012, 03:36 PM
Mindphaser Mindphaser is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 23 Mindphaser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 16 sec
Reputation Power: 0
Uncheck 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;

}

Reply With Quote
  #2  
Old October 21st, 2012, 04:25 PM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 23 m 17 sec
Reputation Power: 2569
That is going to be a lot of lines of code. Programming and computers were invented to save us time

'==' is a comparison operator and '=' is an assignment operator.

Try the following code. Class name of 'card' to your 'array 1' check boxes.
JavaScript Code:
Original - JavaScript Code
  1. function limitChecks(obj) {
  2.     if(obj.checked == false) {
  3.         document.forms['FORM NAME'].elements[obj.name+'_a'].checked = false;
  4.     }
  5. }
  6.  
  7. onload = function() {
  8.     var cards = document.getElementsByTagName('input');
  9.     for (var i=0,x=cards.length; i<x; i++) {
  10.         if (cards[i].className == 'card') {
  11.             cards[i].onclick = function() { limitChecks(this) }
  12.         }
  13.     }
  14. }
HTML4Strict Code:
Original - HTML4Strict Code
  1.     <input type="checkbox" name="card_1" class="card">
  2.    
  3.    
  4.     <input type="checkbox" name="card_1_a">
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
  #3  
Old October 22nd, 2012, 12:04 PM
Mindphaser Mindphaser is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 23 Mindphaser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 16 sec
Reputation Power: 0
Quote:
Originally Posted by Winters
That is going to be a lot of lines of code. Programming and computers were invented to save us time

'==' is a comparison operator and '=' is an assignment operator.

Try the following code. Class name of 'card' to your 'array 1' check boxes.
JavaScript Code:
Original - JavaScript Code
  1. function limitChecks(obj) {
  2.     if(obj.checked == false) {
  3.         document.forms['FORM NAME'].elements[obj.name+'_a'].checked = false;
  4.     }
  5. }
  6.  
  7. onload = function() {
  8.     var cards = document.getElementsByTagName('input');
  9.     for (var i=0,x=cards.length; i<x; i++) {
  10.         if (cards[i].className == 'card') {
  11.             cards[i].onclick = function() { limitChecks(this) }
  12.         }
  13.     }
  14. }
HTML4Strict Code:
Original - HTML4Strict Code
  1.     <input type="checkbox" name="card_1" class="card">
  2.    
  3.    
  4.     <input type="checkbox" name="card_1_a">


Thanks there mod. Your complicated script wasn't the solution. Figured it all out now, I now have the perfect deck of cards code. It handles all 3 decks of 150 cards each PERFECTLY. And 135 of 150 cards from each deck are 'collectable' but my code even handles all this perfectly.

My javascript skills aren't very good, but after figuring out this mess, my knowledge of JS is that much greater.

Thanks again though for trying to help.

Reply With Quote
  #4  
Old October 22nd, 2012, 12:12 PM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 23 m 17 sec
Reputation Power: 2569
I'm glad you have it working, however the script posted did exactly what you asked for. If you required more complexity, you needed to specify.

Reply With Quote
  #5  
Old October 22nd, 2012, 02:10 PM
Mindphaser Mindphaser is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 23 Mindphaser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 16 sec
Reputation Power: 0
Quote:
Originally Posted by Winters
I'm glad you have it working, however the script posted did exactly what you asked for. If you required more complexity, you needed to specify.


No, actually I needed a LESS complicated script lol. I'm still a rookie coder in a few ways.


Cheers

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Uncheck a checkbox if another checkbox is checked

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap