473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I read the value of a radio button?


Folks,

I have a form (called FORM1) - In my INPUT submit tag, I have an onClick
event that I have successfully tested/used to display the value of a TEXT
box using the following function (called via an onClick event)

<script type="text/javascript">
function performPrePostC hecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form 1.myName.value;
alert(h);
return false;
}

How can I read the value of a radio button like I have the text box?

At the moment, if I have it catch myName, I get the value I entered in to
the box named myName in an alert box.

When I change the function to instead catch the value of the radio button
(called hosted) - The alert box says "undefined" .

Are radio buttons handled differently?

I know the above function is basic - I've just narrowed my problem down to
not reading the radio button properly hence no need for me to list the rest
of the code.

All help, via the newsgroup would be much appreciated,
Thanks
Randell D.
Jul 20 '05 #1
4 24427
Randell D. hu kiteb:
Folks,

I have a form (called FORM1) - In my INPUT submit tag, I have an
onClick event that I have successfully tested/used to display the
value of a TEXT box using the following function (called via an
onClick event)

<script type="text/javascript">
function performPrePostC hecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form 1.myName.value;
alert(h);
return false;
}

How can I read the value of a radio button like I have the text box?

At the moment, if I have it catch myName, I get the value I entered
in to the box named myName in an alert box.

When I change the function to instead catch the value of the radio
button (called hosted) - The alert box says "undefined" .

Are radio buttons handled differently?


Radio buttons require an explicit VALUE attribute. CHECKED is an
optional attribute and can be used to specify which options are selected
for initial form display. The VALUE attribute for a text box is whatever
you type there, but typing is unlikely in the context of a radio button.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk
Jul 20 '05 #2

"Fabian" <la****@hotmail .com> wrote in message
news:bq******** *****@ID-174912.news.uni-berlin.de...
Randell D. hu kiteb:
Folks,

I have a form (called FORM1) - In my INPUT submit tag, I have an
onClick event that I have successfully tested/used to display the
value of a TEXT box using the following function (called via an
onClick event)

<script type="text/javascript">
function performPrePostC hecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form 1.myName.value;
alert(h);
return false;
}

How can I read the value of a radio button like I have the text box?

At the moment, if I have it catch myName, I get the value I entered
in to the box named myName in an alert box.

When I change the function to instead catch the value of the radio
button (called hosted) - The alert box says "undefined" .

Are radio buttons handled differently?


Radio buttons require an explicit VALUE attribute. CHECKED is an
optional attribute and can be used to specify which options are selected
for initial form display. The VALUE attribute for a text box is whatever
you type there, but typing is unlikely in the context of a radio button.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk


Okay... I'm familiar with the HTML side of my form and how to set an initial
form display - but how do I use javascript to read my radio value that a
user has selected/checked from radio buttons. My form is called FORM1 and
the following code is what I use to display the radio buttons in the first
place:

Hosted:
<input type="radio" name="hosted" value="local"> Locally
<input type="radio" name="hosted" value="remote"> Remote

randelld

Jul 20 '05 #3

"Randell D." <re************ **********@and. share.com> wrote in message
news:e9Qxb.5183 22$9l5.423971@p d7tw2no...

Folks,

I have a form (called FORM1) - In my INPUT submit tag, I have an onClick
event that I have successfully tested/used to display the value of a TEXT
box using the following function (called via an onClick event)

<script type="text/javascript">
function performPrePostC hecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form 1.myName.value;
alert(h);
return false;
}


I hear so much about "Google being your friend" that I checked their archive
of the newsgroup and found the following answer that I was able to
incorporate into my own solution... My thanks to a chap called "Richard
Hockley" who posted it a few months ago...

http://www.google.ca/groups?q=+%22ra...525ae%240%2411
375%24cc9e4d1f% 40news.dial.pip ex.com&rnum=3
Jul 20 '05 #4
Randell D. hu kiteb:
"Fabian" <la****@hotmail .com> wrote in message
news:bq******** *****@ID-174912.news.uni-berlin.de...
Randell D. hu kiteb:
Folks,

I have a form (called FORM1) - In my INPUT submit tag, I have an
onClick event that I have successfully tested/used to display the
value of a TEXT box using the following function (called via an
onClick event)

<script type="text/javascript">
function performPrePostC hecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form 1.myName.value;
alert(h);
return false;
}

How can I read the value of a radio button like I have the text box?

At the moment, if I have it catch myName, I get the value I entered
in to the box named myName in an alert box.

When I change the function to instead catch the value of the radio
button (called hosted) - The alert box says "undefined" .

Are radio buttons handled differently?

Hosted:
<input type="radio" name="hosted" value="local"> Locally
<input type="radio" name="hosted" value="remote"> Remote


<script language="javas cript">
function foo(loo) {
var i = loo.value;
alert(i);
}
</script>
</head>
<body>
<form name="plar">
<input type="radio" name="yeeq" value="local" onclick="foo(th is);">
Locally
<input type="radio" name="yeeq" value="remote" onclick="foo(th is);">
Remote
</form>

Try what I wrote above. istm that radio buttons have funny stuff going
on because they are defined by multiple input tags. If I had designed
those tgs, I would have made it in the same way the select and option
tag works...

--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #5

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

Similar topics

2
12335
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ... without having to get this value via html, is there any way I can passed the checked value via html .. maybe with syntax like n4.checked.value or something.. Many thanks. <html>
4
4102
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
1
3389
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with ***********************, I've included all the code incase that isn't where the problem is. Any help would be hugely appreciated. Mick
2
2887
by: Stoic | last post by:
I'm offering a selection of three items. One is $25, the second is $50, the third is $100. Along with selection one of the items I need to pass the quantity of the selection. Here is the code now. <tr><td><input type="radio" name="item_name" value="Reduced">Reduced</td><td><input type="radio" name="amount" value="25">$25.00ea.</td></tr> <tr><td><input type="radio" name="item_name" value="Regular">Regular</td><td><input type="radio"...
2
1540
by: darrel | last post by:
I'm using some standard HTML radio buttons (to allow finer javascript interaction) on a web page and would like to catch the selected item on postback. Since they are all ID's uniquely, is there a way to grab only the selected item's value? Or do I need to write an if/then statement to figure out which one is selected? Sample: <input runat="server" id="radio1" name="category" /> <input runat="server" id="radio2" name="category" />
2
3399
by: Mirovk | last post by:
Hi, I have a session variable wich value arrives from a previous .asp but in my actual page I need to modify it based upon a selected value from a radio button. I will try to figure out for better understanding: page1.asp ---session("PaymentMethod") page2.asp ---Depending on the radio button selected the payment
3
2851
by: romano2717 | last post by:
I have a test.php file that contains a set of radio buttons generated inside a loop. then I append the $i variable to the radio button name to have a unique set of radio buttons. the scenario should be this: when i click the submit button, test2.php should display the values of the radio buttons selected in the test.php file FILE: test.php <html> <head> <title>RADIO</title> </head> <body>
1
4076
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two hotspots on the image. One being correct(a) and the other incorrect(b). When the user clicks on the correct hotspot or place on the image, it should score and retain that value until the end of the quiz. At the end of the quiz, there is a submit button...
2
2804
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
7955
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
7883
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,...
0
8261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8019
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
6674
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5839
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
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();...
1
2391
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
0
1223
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.