0

I have page_a.cfm and page_b.cfm. On first page(page_a.cfm) a I have a cfinput (type submit) button that when is clicked it redirects you to page_b.cfm where some queries are run. On this page there is also a button (called "Back") that send you back to page_a. I want the text of the button on page_a.cfm to change based on some condition on page_b.cfm so when I click the "back" button on page_b.cfm and send me back to page_a.cfm the button's text had changed.

On page_a.cfm I have this:

<cfform action="page_b.cfm">
      <cfinput type="Submit" name="multiring_btn" class = "multiringButton" 
value="ACTIVATE after hours voicemail"/>
</cfform>

On page_b.cfm I have this:

<cfif someConditions = true>
    Successfully changed
<cfelse>
    An error has occurred!
</cfif>


<cfform action="page_a.cfm">
    <cfinput type="submit" name="back_btn" value="Back">
</cfform>



<script type="text/javascript">
    function toggleText(multiringButton)  {
        var text = document.getElementById(multiringButton).firstChild;
        text.data = text.data == "ACTIVATE after hours voicemail" ? "DEACTIVATE after hours voicemail" : "ACTIVATE after hours voicemail"; }
</script>

However when I click the button "back" the text of the button on page_a.cfm is still the same.

DoArNa
  • 491
  • 2
  • 9
  • 29
  • 1
    You have two different pages on the server. JavaScript can only modify the (single) page that was delivered from your server. You need to either pass some value back to page_a from page_b so that you can change the value of the button text OR combine the two pages into one so you can manipulate the button text via JavaScript within the combined file. – Miguel-F Apr 27 '17 at 19:32
  • 1
    Nothing to do with the question, but unless it is needed for a legacy app, skip the CF UI controls, ie (`cfform`, `cfinput`, etcetera) and just use plain vanilla html controls. The CF UI stuff is outdated and notoriously quirky. – Leigh Apr 27 '17 at 20:06

1 Answers1

3

You can use a URL parameter. On your form action you can attach the parameter:

<cfform action="page_a.cfm?back=true">
    <cfinput type="submit" name="back_btn" value="Back">
</cfform>

Then on your page a you can pull the URL parameter using JS and change the text of the button. See this post for many ways to get the parameter: How can I get query string values in JavaScript?

Community
  • 1
  • 1
Eeks33
  • 2,245
  • 1
  • 14
  • 17