I am new to javascript and have made a simple form accepting details of login on a web page. I fail to understand how the following code handles the error when written between script tags:

function errorhandler(errormessage,url,line)
{
alert("Error :"+errormessage);
alert("url :" +url);
alert("line :"+line);
return true;
}
onerror=errorhandler;

Could someone help me!!!

There are two ways to handle error

  • onerror - which just allows you to carry on gracefully when there is an error but takes little corrective action
  • The try..catch code block that allows you to trap the error and deal with its consequences

I discuss this, and many other JS issues, in my quickreference guide

JavaScript Quick Reference

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.