/    Sign up×
Community /Pin to ProfileBookmark

Fields active depending on radio selection

Hi,

I found this code that is almost perfect for my application… although I would like to include a text box too that responds to the different radio button states. I have tried a few different things on this line:

zxcgg.ary=zxcgg.getElementsByTagName(‘SELECT’);

but have been unsuccessful. Any help would be greatly appreciated. Thanks!

here’s my code… it works as is.

<html>

<head>
<title></title>
<script language=”JavaScript” type=”text/javascript”>
<!–
// by Vic Phillips (29-07-2005) [url]http://www.vicsjavascripts.org.uk[/url]

function zxcInitGroups(){
zxcg=zxcInitGroups.arguments;
for (zxc0=0;zxc0<zxcg.length;zxc0++){
zxcgg=document.getElementById(zxcg[zxc0]);
zxcgg.ary=zxcgg.getElementsByTagName(‘SELECT’,’TEXT’);
}
zxcD(document.getElementById(‘R1′),’group1′,’group2′,’group3’);
}

function zxcD(){
zxcg=zxcD.arguments;
zxcg1=document.getElementById(zxcg[1]).ary;
zxcg2=document.getElementById(zxcg[2]).ary;
if (zxcg[0].checked){
for (zxc0=0;zxc0<zxcg1.length;zxc0++){
zxcg1[zxc0].removeAttribute(‘disabled’)
}
for (zxc1=0;zxc1<zxcg2.length;zxc1++){
zxcg2[zxc1].setAttribute(‘disabled’,’disabled’)
}
}
else {
for (zxc2=0;zxc2<zxcg2.length;zxc2++){
zxcg2[zxc2].removeAttribute(‘disabled’)
}
for (zxc3=0;zxc3<zxcg1.length;zxc3++){
zxcg1[zxc3].setAttribute(‘disabled’,’disabled’)
}
}
}

//–>
</script>

</head>

<body onload=”zxcInitGroups(‘group1′,’group2′,’group3’);”>
<form>
1.
<input id=”R1″ type=”radio” name=”method” value=”1″ checked=’checked’ onclick=”zxcD(this,’group1′,’group2′,’group3′);” >
<span id=”group1″>
<select size=’1′ name=’id[143]’ >
<option value=’1′>blah</option>
</select>
</span>
<br><br>
2.
<input id=”R2″ type=”radio” name=”method” value=”individual” onclick=”zxcD(this,’group2′,’group1′,’group3′);” >
<span id=”group2″>
<select size=’1′ name=’id[450]’>
<option value=’1′>blah</option>
</select>
</span>
<br><br>
3.
<input id=”R3″ type=”radio” name=”method” value=”textBox” onclick=”zxcD(this,’group3′,’group1′,’group2′);” >
<span id=”group3″>
<input id=”3″ type=”text” name=”id[457]”>
</span>
</form>
</body>

</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzNov 18.2005 — Please place code in [ code ] [ /code ] tags next time.

Which one of Vic's scripts is that?

Could you give more details about exactly what you want the script to do?
Copy linkTweet thisAlerts:
@ojoonlineauthorNov 20.2005 — hi,

thanks for your reply.

I'm trying to include a textfield (3.) as part of the radio group... it works perfectly for the drop boxes in 1. and 2. but I'm not sure what I need to add to the javascript to make the textfield work, ie. disable when it's radio is not selected. here's an example here -> www.textit.com.au/x-testradio.cfm

thanks!

jo
Copy linkTweet thisAlerts:
@ojoonlineauthorNov 23.2005 — Hi Kravvitz,

So, do you think this is possible?

thanks, jo
Copy linkTweet thisAlerts:
@KravvitzNov 23.2005 — Yes, it's possible. I just don't feel like doing it for free.

It looks like you missed a vital part of Vic's demo. Check the X/HTML in his demo again.

[url=http://www.w3.org/TR/html401/types.html#type-name]IDs may not start with a number.[/url]
Copy linkTweet thisAlerts:
@ojoonlineauthorNov 23.2005 — I see. I didn't actually get it from a demo... just a cut and paste version I found. And I'm sure if I went through his demo I still wouldn't have a clue!! lol. My javascript is non-existent... only to make small changes to implement.

How much would you charge to make the modification?

jo
×

Success!

Help @ojoonline 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.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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