Question: How to clear text field value on history.back()

Question

How to clear text field value on history.back()

Answers 1
Added at 2016-12-29 07:12
Tags
Question

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.

Answers
nr: #1 dodano: 2016-12-29 08:12

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.

Source Show
◀ Wstecz