Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q685 How can I prompt the user when they leave my page if they've amended a textarea without submitting the form?

irt.org | Knowledge Base | JavaScript | Form 11 | Q685 [ previous next ]

Q685 How can I prompt the user when they leave my page if they've amended a textarea without submitting the form?

You'll not be able to stop someone from leaving the page in all cases. You can trap people selecting links on your page and then cancel them selectively, but not if the user uses the back of forward button, or selects an item from the history, or types in a url.

For links try:

<SCRIPT LANGUAGE="JavaScript"><!--
var changed = false;

function gothere(href) {
    if (changed) {
        if (confirm("Are you sure?"))
            window.location.href = href;
    }
    else 
        window.location.href = href;
}
//--></SCRIPT>

<FORM onSubmit="changed=false">
<TEXTAREA onChange="changed=true;alert('changed');"></TEXTAREA>
<INPUT TYPE="SUBMIT"
</FORM>

<A HREF="javascript:gothere('http://www.irt.org')">http://www.irt.org</A>

Feedback on 'Q685 How can I prompt the user when they leave my page if they've amended a textarea without submitting the form?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.