/    Sign up×
Community /Pin to ProfileBookmark

Disable two radio buttons with the same name

I have a set of radio buttons with the same name, so that the user can only select one at a time. However, when i try to use javascript to disable the buttons, the javascript only works if the radio buttons have separate names. Does anyone know a solution to this? Here is my code:

if(document.addtocart.zaicprice.options[id].value == “20”)
{
document.addtocart.laminated.disabled = true;
}

Yes<input type=’radio’ checked=’true’ value=’yes’ name=’laminated’>
No<input type=’radio’ value=’no’ name=’laminated’>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@nastyFeb 06.2006 — <form name="test">

<input type="radio" name="radio">

<input type="radio" name="radio">

<input type="submit" value="disable" onclick="disableit(this);return false">

<script language="javascript">

function disableit(which) {

for(var i=0;i<document.all.radio.length;i++) {

document.all.radio[i].disabled = (document.all.radio[i].disabled) ? false : true;

}

which.value = (which.value=="disable") ? "undisable" : "disable";

}

</script>
Copy linkTweet thisAlerts:
@rbailerauthorFeb 06.2006 — Good stuff! thanks a lot.
Copy linkTweet thisAlerts:
@felgallFeb 06.2006 — That code is written for Internet Explorer 4 (the only browser to use document.all exclusively). You should use document.getElementsByTagName to get it to work in all modern browsers.
×

Success!

Help @rbailer 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...