473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how to get radio button value in javascript--

my code doesn't work. undefined is displayed.....how to get a value of radoi button in javascript

[HTML]function enableaddr()
{
alert(document.getElementById('reason').length);
for (var i=0; i < document.getElementById('reason').length; i++)
{
if (document.getElementById('reason[i]').checked)
{
var reason1 = document.getElementById('reason[i]').value;
alert(reason1);
}
}
}

<form action="cust_index.php?action=delete&cid=<?php echo $cid;?>" name="del_form">
<table width="400" border="0" cellpadding="6" align="center" cellspacing="1" class="bg1">
<tr class="bg2"><td>Enter the reason to delete the record with the customer name <?php echo $name;?> :</td></tr>
<tr class="bg2"><td><input type="radio" name="reason" id="reason" value="close" onclick="enableaddr()" />Close</td></tr>
<tr class="bg2"><td><input type="radio" name="reason" id="reason" value="shifta" onclick="enableaddr()" />Shift &nbsp;</td></tr>
<tr class="bg2"><td>Enter the address :&nbsp;&nbsp;&nbsp;<textarea cols="30" rows="4" disabled="disabled" name="shiftaddress" id="shiftaddress"></textarea></td></tr>
<tr class="bg2"><td align="center"><input type="submit" value="submit" class="button"></td></tr>
<input type="hidden" name="reason1" id="reason1" />
</table>
</form>[/HTML]
Apr 2 '08 #1
1 1863
gits
5,390 Expert Mod 4TB
you make the wrong use of getElementById(). first, the id HAS TO be unique in a page ... and so the method could give you just ONE element. you may use something that retrieves you a node list like in the following example:

Expand|Select|Wrap|Line Numbers
  1. function enableaddr() {
  2.     var reasons = document.getElementsByName('reason');
  3.  
  4.     for (var i = 0; i < reasons.length; i++) {
  5.         if (reasons[i].checked) {
  6.             var reason1 = reasons[i].value;
  7.             alert(reason1);
  8.         }
  9.     }
  10. }
  11.  
kind regards
Apr 2 '08 #2

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

Similar topics

1
by: Mokoena | last post by:
I can't seem to do an if statement check on the value returned from a selected radio button (isexistingleague). The code never runs anything within the if statement that tests if "true" is...
3
by: Flip | last post by:
In setting up a radio button group last night, I added two radio buttons, gave each of them their respective name and gave them both the same group name. So far so good. But then when I tried to...
4
by: yawnmoth | last post by:
I'm trying to display a popup showing which radio button is selected and am unable to do so. Every time I try, I get undefined, instead of the value of the particular form variable I'm trying to...
1
by: Mufasa | last post by:
I have a couple of radio buttons that make various things appear/disappear on the screen through JavaScript. All works great. Problem is I'll click a radio button, something will appear, I reload...
4
by: Sonasang | last post by:
Hi , I am creating webpage in ASP. In that page i am using 2 radio button..... Male and female If onclick event fires for the radiobutton i have to update the value in the database as male (if...
5
Claus Mygind
by: Claus Mygind | last post by:
In my script I used to test the value of the radio button to verify which button was selected. I was able to do that because all the buttons have the same name. If I want to use the the proper...
9
by: ameshkin | last post by:
Hi guys, I'm a pretty good PHP programmer, but when it comes to JS, I just dont understand it! But I really need to learn. I'm having trouble doing the simplest thing! When someone clicks...
7
gskoli
by: gskoli | last post by:
Dear all, Let me tell you the scenario , i have called javascript function on radio button selection , Ex. Suppose There are 3 Radio Button . Let us consider i have clicked on one radio...
1
by: lipton | last post by:
how can i compare a mysql table feild value with selected redio button value with php
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.