I have a long list of radio buttons. I am looking for a solution if a radio button is selected, the page scrolls to the beginning of the radio button.
Detail:
I have list of radio button like that:
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault1">
<label class="form-check-label" for="flexRadioDefault1">
Default radio
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault2" checked>
<label id="divtwo" onclick="myMenu()" class="form-check-label" for="flexRadioDefault2">
Default checked radio
</label>
</div>
Js file:
function myMenu() { document.getElementById("divFirst").scrollIntoView(); }
I am looking for a solution, if the user clicks on the first radio button, then the page scrolls to the beginning.
It does not scroll while I click, although I added onclick.
onclick="myMenu()" should be on checkbox not on Label:
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault2" onclick="myMenu()">