JavaScript Code for Error Message

Asked By 20 points N/A Posted on -
qa-featured

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?

SHARE
Answered By 0 points N/A #100508

JavaScript Code for Error Message

qa-featured

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.

 

Login/Register to Answer

Related Questions