/    Sign up×
Community /Pin to ProfileBookmark

Mode selection using radio buttons is working in IE, but not in Firefox

Hi.

I’m using a pair of radio buttons on a webpage that runs a Javascript.
I’ve defined the radio buttons with the following HTML code:

[CODE]
<FORM NAME=”vocabtest”>

<INPUT TYPE=”RADIO” NAME=”transdirection” ID=”trans1″ VALUE=”direct1″ CHECKED>Direction 1
<INPUT TYPE=”RADIO” NAME=”transdirection” ID=”trans2″ VALUE=”direct2″>Direction 2

</FORM>
[/CODE]

The Javascript I’ve added to the page checks the state of these radio buttons with the following code:

[CODE]
if(vocabtest.transdirection.trans1.checked==true) translationdir=1;
if(vocabtest.transdirection.trans2.checked==true) translationdir=2;
[/CODE]

The page seems to be functioning without any problems in IE.
But the mode selection that these radio buttons control isn’t working properly in Mozilla Firefox.

Is there a reason why this code might not be compatible with browsers other than Internet Explorer?
(I’m fairly new to this stuff.)

Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@pj59Jan 12.2005 — Hello!

Your referencing the objects cannot work in Mozilla. Try this:[CODE]
if(document.vocabtest.transdirection[0].checked==true) translationdir=1;
if(document.vocabtest.transdirection[1].checked==true) translationdir=2;
[/CODE]
Regards PJ
Copy linkTweet thisAlerts:
@KorJan 12.2005 — Use [b]document.[/b] as a root for elements' reference.

And ...the radio buttons are a collection of elements with the same name, thus you may use the index of:

if(document.vocabtest.elements['transdirection'][0].checked==true){

translationdir=1;

}

else if(document.vocabtest.elements['transdirection'][1].checked==true){

translationdir=2;

}

You don't need to use the ids so erase them, unless you want to use a DOM reference by all means. In this case, the code should be otherwise.
Copy linkTweet thisAlerts:
@KotoauthorJan 12.2005 — pj59, Kor,

many thanks.

?
Copy linkTweet thisAlerts:
@pj59Jan 12.2005 — From my side: you're welcome, Koto! ?

PJ
×

Success!

Help @Koto 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.19,
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,
)...