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
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