• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Problem with radio button value

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my application i wanted to check if the radio button Yes or No is selected.




While i am using follwowing code to acess radio button value:




When i try to acesss the radio button value i dont get any values. Am i missing something?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is wrong

# var elem= document.getElementById('uploadImage');
# var radioLength = elem.length;

You are looking at a TR and than looking at its length. Add alert statements and you will see it is just a div element, you are not reading form elements.

Why don't you give the radio buttons an id and reference them directly? Other option is to use getElementsByTagName with your getElementById statement.

Eric

 
Divy Prakash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<tr id="uploadImage">

Well i m using a id as given above.Check my code at top left.


Regards,
DP
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(elem[i].checked) {
var radioButton =elem[i].value;
Most likely the problem is occurring due the above line, you have declared the variable called radioButton within if construct, however thats being accessed outside the scope.
}
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know you have an id, that id is WRONG. You are referencing the tr, you are NOT referencing form elements. Use an alert statement and you will see what you are doing in your loop. It is nothing close to what you think is happening.

Eric
 
Divy Prakash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i am really confused.

Can you please elaborate a bit more.'


Thanks,
DP
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


#1 is referencing a tr tag. It is just an element
#2 is looking at the length of a tr tag

#2 has nothing to do with form elements.

Some reason you think that

document.getElementById('uploadImage') is the same thing as document.formName.elements which they are not even close.

As I stated before you want to use getElementsByTagName. I will write it out for you:


Eric
 
Divy Prakash
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whats that "input"?
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic