/    Sign up×
Community /Pin to ProfileBookmark

onclick event on table cells and radios

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;
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 18.2004 — 1) You should not use tables for layout.

2) You should explicitly associate form elements with their labels

[font=monospace]<!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>[/font]
×

Success!

Help @backcg1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...