HighDots Forums  

newbie: reading radio selection

Javascript JavaScript language (comp.lang.javascript)


Discuss newbie: reading radio selection in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SAM
 
Posts: n/a

Default Re: newbie: reading radio selection - 06-21-2008 , 04:40 PM






r_ahimsa_m (AT) poczta (DOT) onet.pl a écrit :
Quote:
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


Reply With Quote
  #2  
Old   
r_ahimsa_m@poczta.onet.pl
 
Posts: n/a

Default newbie: reading radio selection - 06-21-2008 , 04:46 PM






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/

Reply With Quote
  #3  
Old   
Doug Gunnoe
 
Posts: n/a

Default Re: newbie: reading radio selection - 06-21-2008 , 07:12 PM



On Jun 21, 4:46 pm, r_ahims... (AT) poczta (DOT) onet.pl wrote:
Quote:
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.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.