<?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>The Infinite Loop - Beginner&#039;s SEO, Beginner C# &#38; JQuery Tutorials &#187; change javascript alerts</title>
	<atom:link href="http://theinfiniteloopblog.com/tag/change-javascript-alerts/feed/" rel="self" type="application/rss+xml" />
	<link>http://theinfiniteloopblog.com</link>
	<description>Problem. Problem Solved. Loop. - The life of a programmer</description>
	<lastBuildDate>Wed, 17 Aug 2011 15:29:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Custom Javascript Alert and Confirm Dialog boxes</title>
		<link>http://theinfiniteloopblog.com/programming/jscript/custom-javascript-alert-and-confirm-dialog-boxes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=custom-javascript-alert-and-confirm-dialog-boxes</link>
		<comments>http://theinfiniteloopblog.com/programming/jscript/custom-javascript-alert-and-confirm-dialog-boxes/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 18:50:54 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XHTML/CSS]]></category>
		<category><![CDATA[change javascript alert button]]></category>
		<category><![CDATA[change javascript alerts]]></category>
		<category><![CDATA[change javascript button text]]></category>
		<category><![CDATA[change javascript confirm button text]]></category>
		<category><![CDATA[custom dialog boxes]]></category>
		<category><![CDATA[custom javascript alerts]]></category>
		<category><![CDATA[custom javascript dialog boxes]]></category>

		<guid isPermaLink="false">http://scottmoniz.com/programmingBlog/?p=204</guid>
		<description><![CDATA[This article will teach you how to make Custom Javascript Alert and Confirm Dialog boxes, and change the button text on dialog boxes. For the most part, custom alert and confirm dialogs are not possible because alert and confirm dialog boxes are handled by the browser, however, there is a great JQuery plugin that will [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<h2>This article will teach you how to make Custom Javascript Alert and Confirm Dialog boxes, and change the button text on dialog boxes.</h2>
<p>For the most part, custom alert and confirm dialogs are not possible because alert and confirm dialog boxes are handled by the browser, however, there is a great JQuery plugin that will let you customize your alert boxes. If you don't know JQuery, do not worry, because i'll take you through it step by step. This little customization can make your web application that much more professional.</p>
<p>This will show you a little tutorial on how to make the custom alert and confirm dialogs AND <strong>How to return values from a custom confirm dialog box</strong>. This is EXTREMELY important. I have seen a lot of tutorials on how to do this, but none of them talk about actually <strong>retrieving the value of the response  in a custom confirm dialog box.</strong>.</p>
<h2>Custom Javascript Alert Dialog Boxes</h2>
<p><strong>Step 1 : Download <a href="http://docs.jquery.com/Downloading_jQuery">JQuery</a></strong></p>
<p>Click on Current Release, you can click Uncompressed if you want to inspect the code, but you should use minified version for production.</p>
<p>In our site, we will make a folder called scripts, and we will put the jquery.js file into this folder.<br />
We will also make a new file in the same folder named jquery.scripts.js.</p>
<p><strong>Step 2: Download </strong><a href="http://theinfiniteloopblog.com/wp-content/uploads/2009/07/jquery.alerts.js">jquery.alerts (Right click, Save as)</a>  and the css here: <a href='http://theinfiniteloopblog.com/wp-content/uploads/2009/07/jquery.alerts.css'>jquery.alerts.css</a><br />
</a> NOTE: This plugin is no longer supported by http://abeautifulsite.net/, so use it at your own risk.</p>
<p>We will put the jquery.alerts.js into the scripts folder, and the jquery.alerts.css into a styles folder.</p>
<p><strong>Step 3: The Setup</strong><br />
In our webpage we will add the references to these file.</p>
<p>&lt;script type="text/javascript" src="scripts/jquery.js"&gt;&lt;/script&gt;<br />
&lt;script type="text/javascript" src="scripts/jquery.scripts.js"&gt;&lt;/script&gt;<br />
&lt;script type="text/javascript" src="scripts/jquery.alerts.js"&gt;&lt;/script&gt;<br />
&lt;link href="styles/jquery.alerts.css" rel="stylesheet"/&gt;</p>
<p>Once we have all these references in, we're ready to write some jquery.</p>
<p><strong>Step 4: Open jquery.scripts.js</strong><br />
Type</p>
<p>$("document").ready(function(){</p>
<p>});</p>
<p>This sets up a function to be run when our document is ready.</p>
<p>In this document.ready function, type<br />
alert('jquery loaded');</p>
<p>Refreshing your webpage, you should see an alert saying "jquery loaded", if you see this, you have setup jquery correctly. If you do not, check the steps above, or hit CTRL+F5, this does a cache refresh and requests a new copy of all the javascript and css files.</p>
<p>We will add a button to our site.<br />
&lt;input type="button" value="Custom Alert" id="customAlert"/&gt;</p>
<p>In our document ready function, we will hook up a handler to handle the "click" event of this button.</p>
<p>$("document").ready(function(){<br />
$("#customAlert").click(function(){<br />
alert('this is an alert');<br />
});<br />
});</p>
<p>If you refresh your webpage (CTRL+F5) and click the button, you should see a normal javascript popup.<br />
Now, change the alert to jAlert.<br />
jAlert('this is a custom alert', 'this is a custom title');</p>
<p>Upon refreshing the page, and clicking the button, you should see a custom grey alert box.<strong> </strong>The styles can be modified by editing jquery.alerts.css.</p>
<p><strong>If you'd like to read on Custom confirm dialog boxes, please continue reading.</strong><br />
By this point, jquery and the jquery alerts plugin and css should be setup.<br />
Follow the above tutorial until you get to the actual jAlert method.</p>
<p><em>Comment if this helped! <img src='http://theinfiniteloopblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<h2>Custom Javascript Confirm Dialog Boxes</h2>
<p>Now, we will do a <strong>Custom Javascript Confirm Dialog.</strong><br />
The confirm function looks like this<br />
<strong>jConfirm('msg', '[title]', [callback function]);</strong></p>
<p>$("document").ready(function(){<br />
$("#btnID").click(function(){<br />
jConfirm('Would you like Ice Cream', 'msgBox Title', function(r){<br />
if(r){<br />
alert('you replied yes!');<br />
}else{<br />
alert('you replied no!');<br />
}<br />
}<br />
});<br />
});<br />
This is the basic implementation of custom confirm boxes, however you can still customize these a little further.</p>
<h2><strong>Changing Javascript Alert Button Text</strong></h2>
<p>Before calling jAlert or jConfirm, you can set the button text.</p>
<p>$.alerts.okButton="OKAYYYYYYYYYY";<br />
$.alerts.cancelButton="CANCELLLLLLLLLL";</p>
<p>This is also useful for localization.<br />
For example in an english jquery.scripts.js you can have.</p>
<p>$.alerts.okButton = "yes";<br />
$.alerts.cancelButton = "no";</p>
<p>And in a french jquery.scripts.js you can have</p>
<p>$.alerts.okButton="oui";<br />
$.alerts.okButton="non";</p>
<p>Hopefully this helped you add that little extra touch.<br />
For reference, here are the 2 methods, only the msg parameter is required.</p>
<p>jAlert('msg', '[title]', [callback function]);<br />
jConfirm('msg', '[title]', [callback functoin]);</p>
<p>There you have it!<br />
<em><strong>Please comment if this was helpful <img src='http://theinfiniteloopblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </strong></em><br />
Goodluck with your custom javascript!</p>
]]></content:encoded>
			<wfw:commentRss>http://theinfiniteloopblog.com/programming/jscript/custom-javascript-alert-and-confirm-dialog-boxes/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

