alert('Hello');
This is one useful tool to inform or alert the user by displaying some messages. Alert message window will have only one button displaying 'OK' and there is no confirm or cancel button. To get the user input by displaying confirm or cancel buttons we have to use confirm window function. Alerts can be programmed to display different messages based on requirements and it can be programmed by using server side scripting languages.
function show_alert() {
var msg = "Welcome to plus2net.com";
alert(msg);
}
Here msg is the variable and we are displaying the text stored inside the variable msg in the alert box.
<html><head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function show_alert() {
var msg = "Welcome to plus2net.com";
alert(msg);
}
</script>
</head>
<body >
<input type=button value='Click here to display alert message' OnClick="show_alert()">
</body></html>
Here we have displayed a variable data in our alert window. Same way we can display input data of the user from a text box or from any other input field in an alert window. This is used by developers to check the status of the variables at different stage of script execution.
<input type=text id='t1'><br>
<input type=button value='Click here to display alert message' OnClick="show_alert()">
<br><br>
<script type="text/javascript">
function show_alert() {
var msg=document.getElementById("t1").value;
alert(msg);
}
</script>
placidius | 03-05-2012 |
this code has been useful to me, thank you very much for your sharing. |