I am looking to dynamically adjust the number of buttons available for users to select based on their input value.
My initial thought was to use a JavaScript if...else
function to toggle between display: none
and display: block
depending on the input value, but so far, my attempts have been unsuccessful.
<body>
<div><input type="text" id="runners" />Select No. of runners</div>
<br /><br />
<div id="runner1"><button class="open-button btn1" onclick="openForm()" style="display:block;">1</button></div>
<div id="runner2"><button class="open-button btn2" onclick="openForm()" style="display:block;">2</button></div>
<div id="runner3"><button class="open-button btn3" onclick="openForm()" style="display:block;">3</button></div>
<div id="runner4"><button class="open-button btn4" onclick="openForm()" style="display:block;">4</button></div>
<div id="runner5"><button class="open-button btn5" onclick="openForm()" style="display:block;">5</button></div>
<div id="runner6"><button class="open-button btn6" onclick="openForm()" style="display:block;">6</button></div>
<div id="runner7"><button class="open-button btn7" onclick="openForm()" style="display:block;">7</button></div>
<div id="runner8"><button class="open-button btn8" onclick="openForm()" style="display:block;">8</button></div>
<div id="runner9"><button class="open-button btn9" onclick="openForm()" style="display:block;">9</button></div>
<div id="runner10"><button class="open-button btn10" onclick="openForm()" style="display:block;">10</button></div>
</body>
If the user inputs "6" as the number of runners, only six buttons should be visible.