1

I have a ColdFusion condition like this:

<cfif txtTaxFileNo neq "">
    <script>
        alert("NPWP Already Exist");
        history.back();
    </script>
    <cfabort>   
</cfif>

Assume txtTaxFileNo has a value of "123" in the previous page. How can I empty the txtTaxFileNo field? I already tried this:

<cfif txtTaxFileNo neq "">
    <script>
        alert("#JSStringFormat('NPWP Already Exist')#");
        history.back();
        txtTaxFileNo.value = "";
    </script>
    <cfabort>   
</cfif>

However, the textfield on the previous page is not empty. It still has a value of "123". Thanks in advance.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72

1 Answers1

1

Don't usehistory.back() because that restores form state. If you want to load a fresh page, just load a fresh page.

<cfif txtTaxFileNo neq "">
    <script>
        alert("NPWP Already Exist");
        window.location = "form URL here";
        // or, if the URL is the same
        window.location.reload(true);
    </script>
    <cfabort>   
</cfif>

See window.location.reload() docs on MDN.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • thats the problem sir, i have 3 different pages, lets say pages 1, 2, 3. the problem is whenever i navigate the page, the url still same in the page 1, even i go to page 2, 3 or 4 the url still display location on page 1. so if i paste the url, it always back to first page – Anton Prio Hutomo Dec 29 '16 at 07:54
  • 3
    All I can tell you that `history.back()` is the wrong thing to do. I can tell you what to do instead. However, I can't tell you which URL to use. It's your application, you must know. – Tomalak Dec 29 '16 at 08:28
  • cgi.http_referrer might come in handy. – Dan Bracuk Dec 29 '16 at 12:58
  • 2
    @AntonPrioHutomo Another thing to remember, `txtTaxFileNo` is a ColdFusion variable not a JavaScript variable. So it is not available on the client. It can only be manipulated on the ColdFusion server so a reload is necessary – Miguel-F Dec 29 '16 at 12:58