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

newbie: reading radio selection

Hello,
I am learning JavaScript. I created radiobutton group:

<input type="radio" name="building_type" value="N">new</input>
<input type="radio" name="building_type" value="O">old</input>
<input type="radio" name="building_type" value="" checked>n/a</input>

and I want to test selection in javascript:

if (document.announcement.building_type.value != "") ...

My problem is that - whatever is selected -
document.announcement.building_type.value is undefined.
I expected "N", "O", "".
Please help.
/RAM/
Jun 27 '08 #1
2 1039
SAM
r_********@poczta.onet.pl a écrit :
Hello,
I am learning JavaScript. I created radiobutton group:

<input type="radio" name="building_type" value="N">new</input>
<input type="radio" name="building_type" value="O">old</input>
<input type="radio" name="building_type" value="" checked>n/a</input>

and I want to test selection in javascript:

if (document.announcement.building_type.value != "") ...

My problem is that - whatever is selected -
document.announcement.building_type.value is undefined.
to get value of any kind of form's element

function getElementValue(elemt) {
if(elemt.tagName == 'input' && elemt.length)
{ // elemt is radios or checkboxes collection
for(var i=0, L = elemt.length; i<L; i++) {
if(elemt[i].checked) {
elemt = elemt[i];
break;
}
}
}
return elemt.value;
}
if (getElementValue(document.announcement.building_ty pe) != "")
--
sm
Jun 27 '08 #2
On Jun 21, 4:46 pm, r_ahims...@poczta.onet.pl wrote:
Hello,
I am learning JavaScript. I created radiobutton group:

<input type="radio" name="building_type" value="N">new</input>
<input type="radio" name="building_type" value="O">old</input>
<input type="radio" name="building_type" value="" checked>n/a</input>

and I want to test selection in javascript:

if (document.announcement.building_type.value != "") ...

My problem is that - whatever is selected -
document.announcement.building_type.value is undefined.
I expected "N", "O", "".
Please help.
/RAM/
Look at the DOM method getElementsByName

http://www.w3schools.com/htmldom/met...entsbyname.asp

You want something like,

var obj = document.getElementsByName('building_type');

then you should see that obj[0].value == "N" and obj[1].value == "O"
and obj[2].value == "".

Good luck.
Jun 27 '08 #3

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

Similar topics

2
by: entoone | last post by:
I am able to make a selection of information when entering a record, with radio buttons giving the option of yes, or no. Which stores their answer as yes, or no in the database. I then have an...
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 ......
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
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....
4
by: tedqn | last post by:
I have a form with checkboxes and radio buttons which, onClick, run an XmlHttp call to retrieve sub questions for that particular box (AJAX). The problem is if user click on several boxes too fast,...
2
by: Bob Alston | last post by:
I have an application with several forms. Most forms use radio boxes for Yes/No choices. On a few of these, once one option is selected, the user cannot change the selection without moving to...
1
by: Para | last post by:
Hi , I am working on a project using C/C++ in linux environment. Our program right now using the command line(console window) inputs and starts executing. command on console are to start...
10
by: mukeshrasm | last post by:
Hi I have a html in which there is two selection box and two radio button. Radio buttion is of array type. What I want if user will click the radio button then only he/she be able to make...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.