Why am I always getting the same value returned with radio buttons?
-
I am using this code using AJAX. The probelm is no matter what choice is selected I always get the result grade=5. Can anyone help me with why this is the case? Thanks, Steven. <form> <li><input type="radio" id="grade" name="grade" value="5" accesskey="5">Great</li> <li><input type="radio" id="grade" name="grade" value="4" accesskey="4">Good</li> <li><input type="radio" id="grade" name="grade" value="3" accesskey="3">OK</li> <li><input type="radio" id="grade" name="grade" value="2" accesskey="2">Poor</li> <li><input type="radio" id="grade" name="grade" value="1" accesskey="1">Oh, oh</li> <li><input type="radio" id="grade" name="grade" value="0" accesskey="0">What is this?</li> <li><input value="Study now" type="button" onClick="getNewTotals();" > </li> </form>
-
Answer:
What appears to be happening is that you are always getting the value of the first 'grade' element in your page and not the value of the selected 'grade' element which would explain why you keep getting '5' returned (can't tell for sure since a line of your getNewTotals is cut off that returns the grade value). Basically you need to do something like this. Make sure to add the name attribute of 'myform' to your form tag. var val = 0; for( i = 0; i < document.myform.grade.length; i++ ) { // note - remove the spaces after the periods on the next two lines, yahoo messes up long code like this with a bunch of periods if( document. myform. grade[i]. checked == true ) val = document. myform. grade[i]. value; } alert( "val = " + val ); here is the link I found this example on http://www.thescripts.com/forum/thread90522.html
perry er at Yahoo! Answers Visit the source
Other answers
I need to see the function getNewTotals() please... Well function getnewtotals has nothing to do with this... You have a problem with this function... function createQueryString() { var grade= document.getElementById("grade... <you cut this line off, please retype it again> var queryString = "grade=" +grade; return queryString; }
bigbot
Ummm, there's a lot you haven't posted for us to see, but it looks like the function you call during your onClick event is not the same name as the one you posted later in the comments. Anyway, try changing getNewTotals to the same name as the function you think should run, or change the name of the function you defined to be getNewTotals. Otherwise, I'm guessing you just didn't show us getNewTotals?
cdg1111us
Related Q & A:
- Why do I always feel so tired and sleepy?Best solution by Yahoo! Answers
- Why do I always feel so sleepy?Best solution by Yahoo! Answers
- Why do i always lose signal on my mobile?Best solution by Yahoo! Answers
- Why do I always dream about buildings?Best solution by auntyflo.com
- Why do I always dream about my boyfriend leaving me?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.