Problem with radio button value
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
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?
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
# 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
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
<tr id="uploadImage">
Well i m using a id as given above.Check my code at top left.
Regards,
DP
Well i m using a id as given above.Check my code at top left.
Regards,
DP
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
}
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.
}
Swastik
Eric Pascarello
author
Posts: 15385
6
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
Eric
Divy Prakash
Greenhorn
Posts: 10
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Well i am really confused.
Can you please elaborate a bit more.'
Thanks,
DP
Can you please elaborate a bit more.'
Thanks,
DP
Eric Pascarello
author
Posts: 15385
6
posted 16 years ago
#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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
#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
| 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 |








