I have three radio inputs and I want to let the radio inputs return the value of the inputs
uand execute a function when user selects one option.
Here is the code:
console.log(document.querySelector('input[name="radios"]:checked').value);
<form>
<input type="radio" id='HTML'name="radios" value="HTML">HTML<br>
<input type="radio" id="css" name="radios" value="CSS">CSS<br>
<input type="radio" id="javascript" name="radios" value="JavaScript">Javascript<br>
</form>
Thanks for the answer from Parthik Gosar, I could get the value from radio input
.
But the problem is document.querySelector('input[name="radios"]:checked').value
will get the value from the radio input
once the page loaded which is null
.
I just wonder is there some built-in function similar to onclick
where it will execute a function when user select an option or other ways to solve the problem?
Thanks for any responds!
*I know we could use document.getElementById('').checked
to check, but it will execute the function when the page loaded which will not work for me.,