473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

2D array and radio buttons

Uncle Dickie
67 New Member
Hi All,

I am trying to extract some data from a 2D array based on a radio button and drop down combination.

I have the following code but I am not getting a value for the radio button object so the position in the array is always 'undefined'

Expand|Select|Wrap|Line Numbers
  1. <form>
  2.     <input type="radio" name="l2" value=0>&deg;C
  3.     <input type="radio" name="l2" value=1>&deg;F
  4.     <br>
  5.     <br>
  6.     <select name="l0">
  7.         <option value=0>J-Type</option>
  8.         <option value=1>K-Type</option>
  9.         <option value=2>L-Type</option>
  10.     </select>
  11.     <br>
  12.     <br>
  13.     <input type = "button" onClick="myfunc()" value=" Start Logging ">
  14. </form>
  15.  
  16.  
  17.  
  18. <script type="text/javascript">
  19.  
  20. var myarray=
  21. [
  22.     ['J min C','J min F','J max C','J max F'],
  23.     ['K min C','K min F','K max C','K max F'],
  24.     ['L min C','L min F','L max C','L max F']
  25. ]
  26.  
  27. var mxt;
  28. var mnt;
  29.  
  30. function myfunc() 
  31. {
  32.     var a = document.forms[0].l0.value;
  33.     var b = document.forms[0].elements['l2'].value;    
  34.     mnt = myarray[a][b];
  35.     mxt = myarray[a][b+2];
  36.     alert('range = ' + mnt + ' to ' + mxt);
  37. }
  38.  
  39. </script>
  40.  
Can anyone point me in the right direction for getting the data out?

Many thanks
Mar 11 '09 #1
3 3050
Dormilich
8,658 Recognized Expert Moderator Expert
document.forms[0].l2 is a NodeList object (it contains 2 input elements). thus you have to select one of those two first (namely the selected one) to get a value.
Mar 11 '09 #2
Uncle Dickie
67 New Member
Thanks Dormilich- got it working as below:

Expand|Select|Wrap|Line Numbers
  1. <form> 
  2.     <input type="radio" name="l2" value=0>&deg;C 
  3.     <input type="radio" name="l2" value=1>&deg;F 
  4.     <br> 
  5.     <br> 
  6.     <select name="l0"> 
  7.         <option value=0>J-Type</option> 
  8.         <option value=1>K-Type</option> 
  9.         <option value=2>L-Type</option> 
  10.     </select> 
  11.     <br> 
  12.     <br> 
  13.     <input type = "button" onClick="myfunc()" value=" Start Logging "> 
  14. </form> 
  15.  
  16.  
  17.  
  18. <script type="text/javascript"> 
  19.  
  20. var myarray= 
  21.     ['J min C','J min F','J max C','J max F'], 
  22.     ['K min C','K min F','K max C','K max F'], 
  23.     ['L min C','L min F','L max C','L max F'] 
  24.  
  25. var mxt; 
  26. var mnt; 
  27.  
  28. function myfunc()  
  29.     var mego = document.forms[0].l2
  30.     for (var i=0; i<mego.length; i++)
  31.     {
  32.         if (mego[i].checked)
  33.         {
  34.              var b = parseInt(mego[i].value);
  35.         }
  36.     }
  37.     var a = document.forms[0].l0.value;
  38.     mnt = myarray[a][b]; 
  39.     mxt = myarray[a][b+2]; 
  40.     alert('range = ' + mnt + ' to ' + mxt); 
  41.  
  42. </script> 
  43.  
Mar 11 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
thanks have to go to FireBug - Firefox WebDev Extension
Mar 11 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
6
by: juli | last post by:
Hello, I need a control which will contain radio buttons that will be added in a loop. I am using this control a source of some other control. I tried to use group box windows control and to add...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
5
by: Peted | last post by:
I know you can iterate through a collection of radio buttons in a panel, using a "for each in control" type iteration that c# supports, but is it possible to iterate through the radio buttons...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.