JavaScript Radio Object : onblur Event handler

Description

The onblur event handler of radio object is defined in an <input> tag (i.e. <input type="radio" name="rd1" onblur = "JavascriptCode">). It executes some JavaScript code or function when a radio object loses focus either by the pointing device (for example mouse) or by pressing tab key.

Version

Implemented in JavaScript 1.0

Syntax

onblur = "JavascriptCode"

Parameter

JavascriptCode : JavaScript statement or JavaScript function.

Example of Radio object : onblur event handler

In the following web document onblur event handler execute an alert box when a radio object loses focus.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JavaScript radio Object's Event handler : onblur Example</title>
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
function Applealert()
{
if(document.Form1.radio1.checked == true)
{
alert("Apple has lost it's focus.");
}
}
function Orangealert()
{
if(document.Form1.radio2.checked == true)
{
alert("Orange has lost it's focus.");
}
}
//]]>
</script>
</head>
<body>
<h1 style="color: red">JavaScript radio Object's Event handler : onblur</h1>
<h3>Click on the radio button to focus ... and press tab key or mouse click other area of the document to see the onblur event ....</h3>
<hr />
<form name="Form1" action = "#">
<input type="radio"
name="radio1"
onblur="Applealert()" />Apple
<br />
<input type="radio"
name="radio2"
onblur="Orangealert()" />Orange
</form>
</body>
</html>

View the example of radio object's onblur event handler in the browser

Practice radio object's onblur event handler with Online Editor

Supported Browser

Internet Explorer 7 Firefox 3.6 Google Chrome 7 Safari 5.0.1 Opera 10
Yes Yes Yes Yes Yes

See also :

Javascript event handlers.

Javascript object's event handlers.

Please Google+, Like this tutorial on FaceBook, Tweet, save it as bookmark and subscribe with our Feed. Have suggestions? comment using Disqus down this page. Thanks.


share with delicious share with facebook w3r rss  share with digg share with reddit share with stumbleupon share with twitter