User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 429,971 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,575 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3397 | Replies: 2 | Solved
Reply
Join Date: Jan 2007
Posts: 2,565
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 115
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

An array of arrays of of radio buttons

  #1  
May 7th, 2007
OK, I know how to address all of the radio buttons on a page as an array, and address all of the radio buttons in a single group as an array. And I know how to create multidimensional objects in JavaScript.

But how can I create a two-dimensional array of radio buttons and address it in JavaScript?

Let's do a simple set of four groups of radio buttons, each with three selections (the actual set I want to use is much larger, but I can scale up the solution). Each group can have only one selection.
Group 1:  O A  O B  O C
Group 2:  O A  O B  O C
Group 3:  O A  O B  O C
Group 4:  O A  O B  O C

I want to use for loops to count the number of A selections, the number of B selections, and the number of C selections. I also want to look for diagonal lines of three checked buttons.

What I can't figure out is how to name the button groups in the HTML code so I can address all of them in the loops, yet keep them separate for the purpose of having one radio button selection in each group.

I don't want to use the global array of radio buttons on the page, because the number of buttons above this structure in the webpage will vary. I also want to address them in x-y notation.
Last edited by MidiMagic : May 7th, 2007 at 2:42 am. Reason: I can't edit the title????
Daylight-saving time uses more gasoline
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,565
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 115
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: An array of arrays of of radio buttons

  #2  
May 7th, 2007
Nobody knows this?

Also tell me if you don't see any way to do it.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jan 2007
Posts: 2,565
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 115
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: An array of arrays of of radio buttons

  #3  
May 8th, 2007
I solved it myself.

You build an array of objects, then index that.

<html>
<head>
<title>Try out the radio</title>

<style type="text/css">
<!--

.cenx {text-align: center;}
.wfd {width: 100%}

img {padding: 24pt;}
body {background-color: #cccccc; padding: 2%; font-family: Arial, sans-serif;}

-->
</style>

<script type="text/javascript">

function sumitup(){
 var xax = [document.forms.vote.appr1c, document.forms.vote.appr2c, document.forms.vote.appr3c, document.forms.vote.appr4c];
 var sum, grp, x, y;
 var acc = Array(3);

 sum = 0;
 for(x = 0; x < 3; x++){
  acc[x] = 0;
  for(y = 0; y < xax.length; y++){
   grp = xax[y];
   if(grp[x].checked){
    sum = sum + 1;
    acc[x] = acc[x] + 1;
   };
  };
 };
 alert('A: ' + acc[0] + ', B: ' + acc[1] + ', C: ' + acc[2] + ', TOTAL: ' + sum);
};

</script>

</head>
<body>

<form name="vote" id="vote" action="none">
 <p><fieldset>
  <legend>Block 1</legend>
  <input type="radio" name="appr1c" value="yes" />A
  <input type="radio" name="appr1c" value="yes" />B
  <input type="radio" name="appr1c" value="yes" />C
 </fieldset></p>

 <p><fieldset>
  <legend>Block 2</legend>
  <input type="radio" name="appr2c" value="yes" />A
  <input type="radio" name="appr2c" value="yes" />B
  <input type="radio" name="appr2c" value="yes" />C
 </fieldset></p>

 <p><fieldset>
  <legend>Block 2</legend>
  <input type="radio" name="appr3c" value="yes" />A
  <input type="radio" name="appr3c" value="yes" />B
  <input type="radio" name="appr3c" value="yes" />C
 </fieldset></p>

 <p><fieldset>
  <legend>Block 2</legend>
  <input type="radio" name="appr4c" value="yes" />A
  <input type="radio" name="appr4c" value="yes" />B
  <input type="radio" name="appr4c" value="yes" />C
 </fieldset></p>

 <input type="button" id="startx" name="startx" value="GO" onclick="javascript:sumitup()" />
</form>
</body>
</html>
Last edited by MidiMagic : May 8th, 2007 at 2:00 pm.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC