Asked By
amscott
20 points
N/A
Posted on - 04/09/2012
Hello there!
I really need your help on this one experts.
Im new to web programming and Im planning to create an error message display.
Some say I could javascript so I came here to ask.
What is the code for error messages?
JavaScript Code for Error Message
Hi Amscott,
Yes you can do it on Javascript. You can display error to the user whether it is controlled or not. For example, you called a function Connect(). You want to notify the user if the connection succeeded or not. You can use the function alert() to do so.
Here is an example:
<html>
<head>
<script type = "text/javascript">
var bConnected = connect();
if(bConnected == false)
{
alert("Failed to connect");
}
</script>
</head>
</ html>
There are also instances wherein have to create a mechanism so that your code can handle uncontrolled exception without throwing script errors.
You can use the try…catch.. statement.
For example:
Â
<html>
<head>
<script type = "text/javascript">
var errmsg = "";
try
{
call_invalid_function("Hi there");
}
catch(err)
{
errmsg+= err.message;
alert(errmgs);
}
</script>
</head>
</ html>
I hope it helps.
Â