473,786 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to test the 'value' for unclicked radio buttons

i have 2 radio buttons 1 for yes and 1 for no, it is mandatory for one to be
checked, and am purposely leaving both blank on the page

when i tested for .value, when neither was checked, an alert message comes
back with literally 'undetermined',
and i get the message 2x, once for each button
alert("empty prevVolunteer is " + e.value);
i.e, the text in the message box is "empty prevVolunteer undetermined"

i haven't found anything similar to null, true, false, etc for
'undetermined, so i tried slicing it,
alert("empty prevVolunteer is " + e.value.slice(0 ,2));
and got 'ye' for the yes button and 'no' for the no button

so i'm confused, if the alert returned value is 'undetermined' and yet it
slices to the checked value, when neither has been checked, how do you check
if neither one has been checked
Jul 20 '05 #1
2 8485
"bbxrider" <bb*******@comc ast.net> writes:
i have 2 radio buttons 1 for yes and 1 for no, it is mandatory for one to be
checked, and am purposely leaving both blank on the page
I.e., you have code similar to:

<form name="bar">
Yes: <input type="radio" name="foo" value="yes">
No: <input type="radio" name="foo" value="no">
</form>
when i tested for .value, when neither was checked, an alert message comes
back with literally 'undetermined',
I bet it says "undefined" .
and i get the message 2x, once for each button
Only if you ask for it twice.
alert("empty prevVolunteer is " + e.value);
var e = document.forms['bar'].elements['foo'];
alert("value is " + e.value);

alerts the text: "value is undefined"
i haven't found anything similar to null, true, false, etc for
'undetermined,
"undefined" is a the value Javascript gives to uninitialized variables
and nonexisting object properties. If "e.value" is "undefined" , then
it is because e has no value property.

This is correct behavior. The value of "e" in the above is an "Element
Array" (i.e., perhaps not really an array, but it looks sufficiently
like it). It has two elements, one for each radiobutton in the group.

In order to see whether no radiobutton has been selected, you must
check them both. There is no shorthand for "the radiobutton that is
checked".

if (!e[0].checked && !e[1].checked) { // neither selected ...
so i tried slicing it,
alert("empty prevVolunteer is " + e.value.slice(0 ,2));
and got 'ye' for the yes button and 'no' for the no button
The values of the radiobuttons is the one you have assigned them, no
surprice there. But then, you are looking at each button, which is not
the same as looking at the array containing them/
so i'm confused, if the alert returned value is 'undetermined' and yet it
slices to the checked value, when neither has been checked, how do you check
if neither one has been checked


See above ... by checking that neither is checked.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
thanks for the long reply, maybe i was hallucinating and got the undefined
instead of undetermined but after many hours of coding, i can develop
dyslexia
so now after reading more the button have a convenient 'checked' property,
that can be used testing for true and false. the coding will be ugly though.
the undefined should come in handy, and i understand there is also an
undeclared to fine tune all these clarifications

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:ad******** **@hotpop.com.. .
"bbxrider" <bb*******@comc ast.net> writes:
i have 2 radio buttons 1 for yes and 1 for no, it is mandatory for one to be checked, and am purposely leaving both blank on the page


I.e., you have code similar to:

<form name="bar">
Yes: <input type="radio" name="foo" value="yes">
No: <input type="radio" name="foo" value="no">
</form>
when i tested for .value, when neither was checked, an alert message comes back with literally 'undetermined',


I bet it says "undefined" .
and i get the message 2x, once for each button


Only if you ask for it twice.
alert("empty prevVolunteer is " + e.value);


var e = document.forms['bar'].elements['foo'];
alert("value is " + e.value);

alerts the text: "value is undefined"
i haven't found anything similar to null, true, false, etc for
'undetermined,


"undefined" is a the value Javascript gives to uninitialized variables
and nonexisting object properties. If "e.value" is "undefined" , then
it is because e has no value property.

This is correct behavior. The value of "e" in the above is an "Element
Array" (i.e., perhaps not really an array, but it looks sufficiently
like it). It has two elements, one for each radiobutton in the group.

In order to see whether no radiobutton has been selected, you must
check them both. There is no shorthand for "the radiobutton that is
checked".

if (!e[0].checked && !e[1].checked) { // neither selected ...
so i tried slicing it,
alert("empty prevVolunteer is " + e.value.slice(0 ,2));
and got 'ye' for the yes button and 'no' for the no button


The values of the radiobuttons is the one you have assigned them, no
surprice there. But then, you are looking at each button, which is not
the same as looking at the array containing them/
so i'm confused, if the alert returned value is 'undetermined' and yet it slices to the checked value, when neither has been checked, how do you check if neither one has been checked


See above ... by checking that neither is checked.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

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

Similar topics

3
11953
by: Eric Chang | last post by:
I was working on this simple form with radio boxes. And when I click on one of the radio box, it tell me the value is "undefined" Why is that ? I did defined the value of each radio box: <input type=radio name='Usetax' value='basic' onClick='document.myform.amount.value=document.myform.Usetax.value'> <input type=radio name='Usetax' value='no' onClick='document.myform.amount.value=document.myform.Usetax.value'> <input type=radio...
4
24441
by: Randell D. | last post by:
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
2
5431
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 I want to be able to retrieve the selected value from each of the sets of radio buttons.The names of each group of radio buttons is set by the database and I don't know how to retrieve the values because I don't know the names of these radio...
3
2406
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 get the group names selected value, I couldn't find any properties/methods on that object. In fact the object didn't exist for me. Is this correct? When playing with Radio buttons, do you still have to enumerate through all of them to find...
7
13638
by: deepagulati | last post by:
Hi, I need an urgent help from you. When we dynamically genrate any list box (Select Box) it shows one default value as selected. Is there any way that we can deselect that value. I tried with document.form_Name.ListBox_Name.options.selected =
1
5467
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 the page for other reasons and the item disappears. The reason it disappears is I have to set the state initially to invisible so it doesn't show up initially. The radio buttons are html radio buttons not aspx radio buttons so I can have the...
1
4085
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...
5
3603
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at: http://www.geocities.com/usenet_daughter/javascript_radio.htm but for some reason I can only get a value if I hard code the control name.
6
2799
by: tvnaidu | last post by:
Hi: Any stress test html script to test web page contains few radio buttons and apply. I have web page contains 8 radio buttons, just select on / off using radio button, then at the bottom, click on "apply", I need some script to do this overnight to stress the system, please let me know if any script availbale, appreciated. TV.
0
9497
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
10110
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
8993
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...
0
6749
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
5398
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.