/    Sign up×
Community /Pin to ProfileBookmark

duh, what’s wrong with this code?

[CODE]function submitForm(newvalue){

if (document.layers){
//Netscape 4 specific code
document.layers[“feedchooser”].nfs.value=newvalue;
document.layers[“feedchooser”].submit();
} else
if (document.getElementById){
//Netscape 6 specific code
document.getElementById(“feedchooser”).nfs.value=newvalue;
document.getElementById(“feedchooser”).submit();
} else
if (document.all) //IE4+ specific code
document.all[“feedchooser”].nfs.value=newvalue;
document.all[“feedchooser”].submit();
} else{

document.feedchooser.nfs.value=newvalue;
document.feedchooser.submit();
}
}[/CODE]

Can’t figure it out, it works without the browser clauses and with just the final else content. Must be syntax error but it looks fine? Any help much appreciated

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 04.2006 — Twice I see an "else" not followed by a "{".
Copy linkTweet thisAlerts:
@KorAug 04.2006 — I am thinking at something else. In my opinion the code is absolutelly usles

the function
<i>
</i>function submitForm(newvalue){
document.feedchooser.nfs.value=newvalue;
document.feedchooser.submit();
}

is enough, as I guess that this basic syntax is recognized by absolute all the browsers, old or new, so that the detector/syntax for NS4/DOM/IE4 is usless.
Copy linkTweet thisAlerts:
@mcpalmerauthorAug 04.2006 — if else syntax goes together without a { as far as i know. Are you coding on a different planet? ?

Ok, i will leave it simple. I thought I needed these browser detections to make it cross-browser comaptible. When should these detectors be used then?
Copy linkTweet thisAlerts:
@mcpalmerauthorAug 04.2006 — Ah i just seen a mistake, no bracket after 3rd if. jeez
Copy linkTweet thisAlerts:
@KorAug 04.2006 — if else syntax goes together without a { as far as i know. Are you coding on a different planet? ?

Ok, i will leave it simple. I thought I needed these browser detections to make it cross-browser comaptible. When should these detectors be used then?[/QUOTE]


When you are dealing with form's elements, the "universal" syntax will cover all the browsers, as far as I know

document.formname.elementname

or the JSON variants

document.forms['formname'].elements['elementname']

document.['formname']['elementname']

The "detector" might be used in case you need to refere other elements than forms' elements, images, frames and links.

Even so, this kind of "detector" still remains usless. Almost nobody uses NS4, and absolutely nobody uses IE4 these days.

Only if you are coding for some small browsers for mobile phones, poket PCs or things like that, you may encouter some problems, as most of those "mini" browsers (Pocket IE, Mobile Opera 8, Minimo....) do not handle DOM too well (or not at all)
Copy linkTweet thisAlerts:
@mcpalmerauthorAug 04.2006 — ok, thanks for the heads up. I never use any browser except latest ie and firefox so like to be corss broswer just in case, but it seems you are probably right and i am being over-cautious.
Copy linkTweet thisAlerts:
@CharlesAug 04.2006 — if else syntax goes together without a { as far as i know. Are you coding on a different planet? ?[/QUOTE]You've omitted the opening bracket but included the closing one.
×

Success!

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