faqts : Computers : Programming : Languages : JavaScript : Forms : Labels

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 31 people (55%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

Using LABEL, how can this be used to select/deselect a radio button associated with it?

May 10th, 2001 13:44
jsWalter,


Try this little sample.
Works great for check boxes too!
Walter
============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Radio Button / Label test</title>
</head>
<script language='JavaScript1.2'>
function labelClick ( sentObj )
{
	// What is this guys name
	objName = sentObj.name;
	// Strip off 'lb_'
	objName = objName.substr(3, objName.length);
	// click on the corrosponding check box
	ckObj = eval ( 'document.all.' + objName );
	ckObj.click();
	ckObj.blur();
}
</script>
<body>
	<input type='radio'
	       name='rdA'
		   id='one'
	       value='menu'
	       checked
	       XonClick='setOption( this )'>
	<span name='lb_one'
		  id='lb_one'
		  onClick='labelClick( this )'> Check One </span>
<p>
	<input type='radio'
	       name='rdA'
		   id='two'
	       value='button'
	       XonClick='setOption( this )'>
	<span name='lb_two'
		  id='lb_two'
		  onClick='labelClick( this )'> Check Two </span>
</body>
</html>