Sunday 25 August 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...