DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How To Display Alert

12.26.2011
| 2496 views |
  • submit to reddit
        A JavaScript alert is a simple window containing a message.

Here is what the code looks like — it's just one line (inside the JavaScript tag):
<script language="javascript" type="text/javascript">
alert('This is what an alert message looks like.');
</script>
The text inside the parentheses is what is shown in the alert message. If you want to show a string of literal text, enclose the text in quotes. To display variable values, enter the variable name without quotes. You can also combine variable values and text strings by using the + sign. For example:
function showAlert() {
	var country = "Fiji";
	var city = "Suva";
	alert('The city of ' + city + ' is located in ' + country + '.');
}

<input type="button" value="Click Here" onClick="showAlert();">

<a href="http://www.java-forums.org/blogs/spring-framework/"><strong>Spring Framework</strong></a>