Sunday, August 25, 2019

html - I can't get the onclick attribute on radio buttons to execute javascript functions

Well, as my title suggests, I'm having a little difficulty in executing javascript functions using radio buttons. I would love to have an alert box pop-up wen I select a radio button, but my code seems to ever be working against my "love(s)". Please help me out.



Here's my HTML, it isn't much.






Question One






Question One


Calculate the area of a circle or a cube




Choose shape to find area














and here is the javascript



var radios = document.getElementsByName("shape");
var len = radios.length;

function checkRadios()
{
for(int i = 0; i < len; i++)
{

if(radios[i].checked)
{
alert(radios[i].getAttribute("value") + " selected.");
}
}
}


I feel like I need to add that, i am just a beginner in js and will appreciate if the help isnt too complicated. i.e, i just want basic javascript without any libraries such as jquery, as those will be too difficult for me to understand at the moment.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...