Home : Internet : JavaScript : Alert

JavaScript Alert

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();">

This will create the following button - click it to see the alert:


Remember, text inside quotes will be used literally, text with no quotes is assumed to be a variable.