Paul Rubenstein Paul Rubenstein - 7 months ago 34
HTML Question

Create variable number of buttons for an html form

I'm trying to make some changes to a questionnaire. Currently on each page there is an html form which has 3 submit buttons with values "next", "back", and "home". The value of the button gets passed through to the java controlling everything so that it knows which page to load next.

What I want to do is have a button along the bottom for each page in the questionnaire - however, this number varies between questionnaires.

The total number of pages is passed through as $(totalNumber) by some freemarker code. I'm new to programming, so instinctively I want to write some kind of "for" loop in javascript that will create a new button each loop and increment a dummy variable to get the right number of buttons, but I can't work out how to do this (and I'm not sure if this is the right way of going about this!)

Thanks for any help!


Assuming you totalPages is at least 1:

<#list 1..totalPages as pageNumber>
   <input type="button" value="${pageNumber}" onclick="goToPage(${pageNumber})" />

The HTML (using input button, onclick, etc.) is not part of the advice... I just show how to use FreeMarker.