Codes
A simple java script error Handling Example.
We can use try catch block in java script for error handling.this is a example for use of try catch
<head>
<title></title>
<script type="text/javascript">
var result; //Global Variable function CalCulate()
{
try { //try Block
var a = document.getElementById("txt1").value;
var b = document.getElementById("txt2").value;
var c = a / b;
result = c;
}
catch (e) { //error handling if you try to divide by zero it will generate exception.
result = e;
}
finally { //this block will execute always either work try block or catch block
mydiv.innerHTML = result;
}
}
</script>
</head>
<body>
<div>
<input type="text" id="txt1" />
<input type="text" id="txt2" />
<input type="button" name="btn1" onclick="CalCulate()" value="Click" />
<div id="mydiv"></div>
</div>
</body>
</html>
Download File
<html>
<head><title></title>
<script type="text/javascript">
function match() {
var a = document.getElementById("txt1").value;
var b = document.getElementById("txt2").value;
if (a == b) {
result.innerHTML = "match";
}
else {
result.innerHTML = "not match";
}
}
</script>
</head>
<body>
<input type = "text" id = "txt1" />
<input type = "text" id = "txt2" onKeyUp="match()" />
<div id="result" />
</body>
</html>
Check match between two text box value with JavaScript.
<html>
<head><title></title>
<script type="text/javascript">
function match() {
var a = document.getElementById("txt1").value;
var b = document.getElementById("txt2").value;
if (a == b) {
result.innerHTML = "match";
}
else {
result.innerHTML = "not match";
}
}
</script>
</head>
<body>
<input type = "text" id = "txt1" />
<input type = "text" id = "txt2" onKeyUp="match()" />
<div id="result" />
</body>
</html>
0 Comments:
Post a Comment
Thanks a lot.
Subscribe to Post Comments [Atom]
<< Home