0

Can someone help me?

I want a function to run if a radio button is checked. I do it this way and don't why it's wrong |html| <form onsubmit="return check()"> yes<input type="radio" name="q_1" id="yes_1" value="yes"/> <br> no<input type="radio" name="q_1" id="no_1"/> <input type="submit" value="submit"></input |javascript| function check() { var q_1_yes = document.getElementById('yes_1'); var q_1_no = document.getElementById("no_1").checked; if (q_1_yes.checked == "yes") { console.log("hi"); } };

27th Nov 2016, 5:49 AM
KidCoder
KidCoder - avatar
1 Answer
0
`.checked` is a bool, so, simply evaluate if it's true. I.e ```js if(q_1_yes.checked) { // execute code } ``` EDIT: ignore my formatting, hoped this forum supported markdown
27th Nov 2016, 8:43 AM
Jared Allard
Jared Allard - avatar