473,761 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unable to do an alert for a radio button value

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 get. Here's my
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="">
<input type="radio" name="testvar" value="1"
checked="checke d">option # 1<br>
<input type="radio" name="testvar" value="2">optio n # 2<br>
<input type="radio" name="testvar" value="3">optio n # 3<br>
</form>
<br>
<a href="#" onclick="alert( document.forms[0].testvar.value) ; return
false">click me</a>
</body>
</html>

If I just use the default selections, it seems like I should be getting
an alert that says "1", but I'm not. I'm getting an alert that says
"undefined" and I don't know why. Any ideas would be appreciated -
thanks!

Oct 19 '06 #1
4 2351

"yawnmoth" <te*******@yaho o.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...

<a href="#" onclick="for(va r i=0; !document.forms[0].testvar[i]; i++){};
alert(document. forms[0].testvar[i].value); return false">click me</a>


Oct 19 '06 #2

yawnmoth wrote:
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 get. Here's my
code:

<snip>

If I just use the default selections, it seems like I should be getting
an alert that says "1", but I'm not. I'm getting an alert that says
"undefined" and I don't know why. Any ideas would be appreciated -
thanks!
This problem appears to be exclusive to radio buttons since the onclick
event in the anchor tag works just fine in this example (the only thing
that's changed is what testvar is):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="">
<input type="hidden" name="testvar" value="1">
</form>
<br>
<a href="#" onclick="alert( document.forms[0].testvar.value) ; return
false">click me</a>
</body>
</html>

Any ideas?

Oct 19 '06 #3

nutso fasst wrote:
"yawnmoth" <te*******@yaho o.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...

<a href="#" onclick="for(va r i=0; !document.forms[0].testvar[i]; i++){};
alert(document. forms[0].testvar[i].value); return false">click me</a>
Hmmm - I guess we posted at the same time. Anyway, that seems to do it
- thanks!

Oct 19 '06 #4

"yawnmoth" <te*******@yaho o.comwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
>
nutso fasst wrote:
"yawnmoth" <te*******@yaho o.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...

<a href="#" onclick="for(va r i=0; !document.forms[0].testvar[i]; i++){};
alert(document. forms[0].testvar[i].value); return false">click me</a>
Hmmm - I guess we posted at the same time. Anyway, that seems to do it
Oops. Actually, it won't do it because I left out the checked property in
the test. I meant to type:

<a href="#" onclick="for(va r i=0; !document.forms[0].testvar[i].checked;
i++){};
alert(document. forms[0].testvar[i].value); return false">click me</a>

But even that is a bit dangerous. Prolly should be:

<a href="#" onclick="for(va r i=0; !document.forms[0].testvar[i].checked && i
< document.forms[0].testvar.length ; i++){};
alert(document. forms[0].testvar[i].value); return false">click me</a>
SORRY!

nf

Oct 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2299
by: Arun Nair | last post by:
Hi, I have the following jsp page. I am able to view only a part of it(until the occurence of the first City text box). If i remove the first few fields from the page, I am able to see a few more fields at the bottom. My form class contains all the properties that are used in the jsp page. I don't know what I am doing wrong. I am using struts1.1 & JDK 1.4.2.
8
10813
by: Nige | last post by:
Is it possible to create an alert box when a radio button is selected? I have a group of three, and I want a different alert for each one. -- Nige Please replace YYYY with the current year ille quis mortem cum maximus ludos, vincat
4
3281
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> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
8
5903
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the control. See the code below * Page.aspx: <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Webspace.Test" %>
2
2317
by: xazos79 | last post by:
Hi All, I've come across the problem of not being able to re-enable a radio button with javascript if its initial state has been disabled in the Page_Load() method of the code behind. Might i add that it behaves fine in Firefox, but IE is unable to re-enable the radio button. IE is fine if the radio button starts in an enabled state.
6
4646
by: Ian Davies | last post by:
Hi me again, sorry to be a pain. Ive been struggling with this one all day. Hope you can understand whats happening. First my script is below. Have a look and I'll explain at the bottom what it does so far and is failing to do ******************************* <?php session_start(); header("Cache-control: private"); //IE 6 Fix include("myconn.php");
10
6103
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
1
1962
by: truptidalia | last post by:
Hello, I am trying to add 2 RadioButtons in a form in js dynamically. I can see 2 radiobutttons, but no text. On clicking them, their is no selection. One of them is selected. I need to retrive their vakue on button click. The form is added in a div which is present in html form (that is not dynamically created). Form & all other elements are created dynamically & appended to div elemetn whch is present in html. The code is : ...
2
2812
by: runway27 | last post by:
i am using a self submitting form <form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="test1"> i need to do a validation of textfields, checkboxes, radio buttons i am able to read, display and validate textfields after the form has been submitted however i am getting an error for checkbox and radio buttons.
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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 we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.