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' -
<form>
-
<input type="radio" name="l2" value=0>°C
-
<input type="radio" name="l2" value=1>°F
-
<br>
-
<br>
-
<select name="l0">
-
<option value=0>J-Type</option>
-
<option value=1>K-Type</option>
-
<option value=2>L-Type</option>
-
</select>
-
<br>
-
<br>
-
<input type = "button" onClick="myfunc()" value=" Start Logging ">
-
</form>
-
-
-
-
<script type="text/javascript">
-
-
var myarray=
-
[
-
['J min C','J min F','J max C','J max F'],
-
['K min C','K min F','K max C','K max F'],
-
['L min C','L min F','L max C','L max F']
-
]
-
-
var mxt;
-
var mnt;
-
-
function myfunc()
-
{
-
var a = document.forms[0].l0.value;
-
var b = document.forms[0].elements['l2'].value;
-
mnt = myarray[a][b];
-
mxt = myarray[a][b+2];
-
alert('range = ' + mnt + ' to ' + mxt);
-
}
-
-
</script>
-
Can anyone point me in the right direction for getting the data out?
Many thanks
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.
Thanks Dormilich- got it working as below: -
<form>
-
<input type="radio" name="l2" value=0>°C
-
<input type="radio" name="l2" value=1>°F
-
<br>
-
<br>
-
<select name="l0">
-
<option value=0>J-Type</option>
-
<option value=1>K-Type</option>
-
<option value=2>L-Type</option>
-
</select>
-
<br>
-
<br>
-
<input type = "button" onClick="myfunc()" value=" Start Logging ">
-
</form>
-
-
-
-
<script type="text/javascript">
-
-
var myarray=
-
[
-
['J min C','J min F','J max C','J max F'],
-
['K min C','K min F','K max C','K max F'],
-
['L min C','L min F','L max C','L max F']
-
]
-
-
var mxt;
-
var mnt;
-
-
function myfunc()
-
{
-
var mego = document.forms[0].l2
-
for (var i=0; i<mego.length; i++)
-
{
-
if (mego[i].checked)
-
{
-
var b = parseInt(mego[i].value);
-
}
-
}
-
var a = document.forms[0].l0.value;
-
mnt = myarray[a][b];
-
mxt = myarray[a][b+2];
-
alert('range = ' + mnt + ' to ' + mxt);
-
}
-
-
</script>
-
Dormilich 8,658
Recognized Expert Moderator Expert
thanks have to go to FireBug - Firefox WebDev Extension
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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>...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |