Click to See Complete Forum and Search --> : onclick event on table cells and radios


backcg1
08-18-2004, 01:33 PM
i have a table with a set of radio buttons on each row. Each radio button is in it's own cell. I would like to enlarge the hit area of the radio buttons by using javascript to use an onclick event in the <td> element where if the user clicks anywhere in that cell, that cell's radio button is selected. I tried this and there was a script error and did not work. Do onclick event on <td> elements not work? Is there a better way to enlarge the hit area of a radio button? any help would be appreciated, thanks!

-Cris

here's some quick summary code of what i tried, don't mind the syntax:

<td onClick="selectRD('radioid1')">
<input type="radio" name="rd" id="rd1" value="1">radio 1
</td>

...javascript>
function selectRD(id){
document.getElementById(id).checked = true;
}

nitwit
08-18-2004, 01:39 PM
http://www.w3schools.com/tags/tag_label.asp

Charles
08-18-2004, 01:43 PM
1) You should not use tables for layout.

2) You should explicitly associate form elements with their labels

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

<style type="text/css">
<!--
fieldset {padding:1ex; width:10em}
label {border:solid 1px #000; display:block; margin:1ex}
-->
</style>

</head>
<body>
<form action="someScript.pl">
<fieldset>
<legend>Example</legend>
<label onclick="this.firstChild.checked = true"><input name="foo" type="radio"> Fee</label>
<label onclick="this.firstChild.checked = true"><input name="foo" type="radio"> Fie</label>
<label onclick="this.firstChild.checked = true"><input name="foo" type="radio"> Foe</label>
<label onclick="this.firstChild.checked = true"><input name="foo" type="radio"> Fum</label>
</fieldset>
</form>
</body>
</html>