<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Show alert when there is unsaved changes &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/show-alert-when-there-is-unsaved-changes/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 29 Sep 2015 09:00:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Show alert when there is unsaved changes &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Check for any unsaved changes in page</title>
		<link>https://www.sibeeshpassion.com/check-for-any-unsaved-changes-in-page/</link>
					<comments>https://www.sibeeshpassion.com/check-for-any-unsaved-changes-in-page/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 29 Sep 2015 00:04:14 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Check for any unsaved changes in page]]></category>
		<category><![CDATA[Show alert when there is unsaved changes]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10714</guid>

					<description><![CDATA[In this post we will discuss how we can check for any unsaved changes in the page by using JQuery. Normally this may need to be implemented in an application where we need to give any alert if any user try to reload the page when there any unsaved changes in the page. I hope you will like this. Background I was creating a page where I have some text boxes, So I wanted to give an alert if user try to get away from the page with out saving the data entered. Using the code First of all we [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss how we can check for any unsaved changes in the page by using <a href="http://sibeeshpassion.com/tag/JQuery/" target="_blank">JQuery</a>. Normally this may need to be implemented in an application where we need to give any alert if any user try to reload the page when there any unsaved changes  in the page. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>I was creating a page where I have some text boxes, So I wanted to give an alert if user try to get away from the page with out saving the data entered. </p>
<p><strong>Using the code</strong></p>
<p>First of all we will create a page and a html table.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Check for any unsaved changes in page&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;table class=&quot;table&quot; border=&quot;1&quot; style=&quot;width: 40%&quot;&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Sibi&lt;/td&gt;<br />
            &lt;td&gt;Ajay&lt;/td&gt;<br />
            &lt;td&gt;&lt;input class=&quot;text&quot; type=&quot;text&quot;  /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Ansu&lt;/td&gt;<br />
            &lt;td&gt;Akhil&lt;/td&gt;<br />
            &lt;td&gt;&lt;input class=&quot;text&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Shanto&lt;/td&gt;<br />
            &lt;td&gt;Libin&lt;/td&gt;<br />
            &lt;td&gt;&lt;input class=&quot;text&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    &lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p>Now if you run your page and, you can see the table.</p>
<div id="attachment_10716" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_11-e1443423241572.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-10716" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_11-e1443423241572.png" alt="Check for any unsaved changes in page" width="650" height="83" class="size-full wp-image-10716" srcset="/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_11-e1443423241572.png 650w, /wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_11-e1443423241572-300x38.png 300w, /wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_11-e1443423241572-400x51.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10716" class="wp-caption-text">Check for any unsaved changes in page</p></div>
<p>No we will create a bool variable which will be true when there is an unsaved data.</p>
<p>[js]<br />
var unsaved = false;<br />
[/js]</p>
<p>What next? We will add call to an existing function when user reloads the page. Sounds good?</p>
<p>[js]<br />
window.onbeforeunload = unloadPage;<br />
[/js]</p>
<p>As you can see we are calling a function <em>unloadPage</em>, preceding is the function definition.</p>
<p>[js]<br />
 function unloadPage() {<br />
            if (unsaved) {<br />
                return &quot;You have unsaved changes on this page.&quot;;<br />
            }<br />
        }<br />
[/js]</p>
<p>Now please run your page and type anything in the text box given, then reload your page.<br />
You will get an alert of <em>You have unsaved changes on this page.</em>. Shall we check that?</p>
<div id="attachment_10717" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_2-e1443423675762.png"><img decoding="async" aria-describedby="caption-attachment-10717" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_2-e1443423675762.png" alt="Check for any unsaved changes in page" width="650" height="260" class="size-full wp-image-10717" srcset="/wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_2-e1443423675762.png 650w, /wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_2-e1443423675762-300x120.png 300w, /wp-content/uploads/2015/09/Check_for_any_unsaved_changes_in_page_2-e1443423675762-400x160.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10717" class="wp-caption-text">Check for any unsaved changes in page</p></div>
<p>We have done it finally.</p>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Check for any unsaved changes in page&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        var unsaved = false;<br />
        $(document).on(&#8216;change&#8217;, &#8216;.table .text&#8217;, function () {<br />
            unsaved = true;<br />
        });</p>
<p>        $(document).on(&#8216;mouseover&#8217;, &#8216;.table td&#8217;, function () {<br />
            $(this).attr(&#8216;title&#8217;, $(this).text());<br />
        });<br />
        function unloadPage() {<br />
            if (unsaved) {<br />
                return &quot;You have unsaved changes on this page.&quot;;<br />
            }<br />
        }<br />
        window.onbeforeunload = unloadPage;<br />
    &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;table class=&quot;table&quot; border=&quot;1&quot; style=&quot;width: 40%&quot;&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Sibi&lt;/td&gt;<br />
            &lt;td&gt;Ajay&lt;/td&gt;<br />
            &lt;td&gt;<br />
                &lt;input class=&quot;text&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Ansu&lt;/td&gt;<br />
            &lt;td&gt;Akhil&lt;/td&gt;<br />
            &lt;td&gt;<br />
                &lt;input class=&quot;text&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Shanto&lt;/td&gt;<br />
            &lt;td&gt;Libin&lt;/td&gt;<br />
            &lt;td&gt;<br />
                &lt;input class=&quot;text&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    &lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Have you ever faced this requirement in your programming life? Does this article helps you in anyway? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can. Have a happy coding!.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/check-for-any-unsaved-changes-in-page/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
