Question

How do I increment a Cold Fusion session variable onClick?

<input type="submit" value="Next Page" class="button" onClick="incrementMySessionVariable">

Currently the button reloads the page on submit (form), but I need to increment my current page session variable onClick.

When the user clicks the button I need to increment the (CFSET SESSION.currentPage +=1) or decrement (CFSET SESSION.currentPage +=-) the session variable, so I can keep track of what page the user(s) are currently on to calculate if the previous page or next page is disabled as well as the table rows to show.

Was it helpful?

Solution

If you give the button a name, such as nextpage then a nextpage var will appear when the button click reloads the page.

<input type="submit" value="Next Page" class="button" name="nextpage">

So, now that you've named the button, add this to near the top of your cfm page (or at least before you start reading SESSION.currentpage)

<cfif isDefined("nextpage")><cfset SESSION.currentPage += 1></cfif>

This will work for a previous page button as well. That button should have name="prevpage" and then add a similar line like this:

<cfif isDefined("prevpage")><cfset SESSION.currentPage -= 1></cfif>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top