I'm trying to get onclick event in html radio buttons to call a function in JavaScript program.
When I use button, it works:
HTML5:
<!DOCTYPE html>
<html lang="en">
<head>
...
<script src="index.js"></script>
...
</head>
<body>
<button type="button" class="btn btn-default" onclick="clickedButton1()">Button1</button>
...
</body>
</html>
JavaScript (in index.js):
function clickedButton1 () {
console.log("clickedButton1")
}
But when I use radio button, the onclick does not call the function:
HTML5 (in the same file above):
<section id="radioButtons">
<form action="" method="post" name="radioButtons" id="radioButtons">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="radios" id="radio1" onclick="test()"> Yes
</label>
<label class="btn btn-primary">
<input type="radio" name="radios" id="radio2" onclick="test()"> No
</label>
</div>
</form>
</section>
Javascript (in index.js):
function test () {
console.log ("test")
}
What's wrong with my code? Any help?
Aucun commentaire:
Enregistrer un commentaire