473,387 Members | 1,641 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,387 software developers and data experts.

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 performPrePostChecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form1.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 24416
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 performPrePostChecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form1.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 performPrePostChecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form1.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.518322$9l5.423971@pd7tw2no...

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 performPrePostChecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form1.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.pipex.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 performPrePostChecks()
{
// myName being an iput text box
// hosted being an input radio box
h=document.form1.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="javascript">
function foo(loo) {
var i = loo.value;
alert(i);
}
</script>
</head>
<body>
<form name="plar">
<input type="radio" name="yeeq" value="local" onclick="foo(this);">
Locally
<input type="radio" name="yeeq" value="remote" onclick="foo(this);">
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
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 ......
4
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...
1
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...
2
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....
2
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...
2
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...
3
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...
1
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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...
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,...

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.