0

When I select a radio button then click the download button, nothing happens. No alert shows up or anything.

Here is my code right now:

HTML:

<form id="Resume_Select">
<input type="radio" name="resume_type" value="Economics" >Economics
<br />
<input type="radio" name="resume_type" value="MIS" >Management Information Systems
<br />
<button onClick="resume_select()"> Download</button>
</form>

JavaScript:

<script>
    function resume_select(){
    var radios = document.getElementByName('resume_type');
    for(var i = 0, length = radios.length; i<length;i++){

        if(radios[i].checked){
            var resume = radios[i].value;
            alert(radios[i].value);
            break;
        }
    }

</script>
3
  • 1
    @TimRijckaert elaborate please. I took the loop from an answer I found for someone with the same question and that is the loop they used. Commented Mar 25, 2015 at 0:32
  • @TimRijckaert I'm assuming you mean the ", length..." Part? Because I was confused with that too. I never wrote a for loop that used a comma. But I just took the guys word. I'll change that back to a semicolon and then get the length variable before the loop starts. That would be better, correct? Commented Mar 25, 2015 at 0:36
  • The initialisation part of the for loop is valid. It's caching the length of the HTMLCollection rather than calculating it each iteration. Commented Mar 25, 2015 at 0:41

1 Answer 1

4

It should be getElementsByName plural not getElementByName. First thing that jumped at me.

Sign up to request clarification or add additional context in comments.

8 Comments

You can simplify your loop like so: for(i = 0; i<radios.length; i++){ ... }
Okay, I will give that a try. Sounds like a simple enough fix.
will do! Just got home, so I am testing it now
That's because you have everything inside form tags. So two options remove them or create a input type button with the on click event attached to it. I noticed that issue when I tested your code on jsfiddle so instead of using a button use an input of type button
@atomCode took out the form tags. Still nothing. No alert.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.