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

瘦欲@ 提交于 2019-12-11 07:56:00

问题


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.


回答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.



来源:https://stackoverflow.com/questions/41374641/how-to-clear-text-field-value-on-history-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!