/    Sign up×
Community /Pin to ProfileBookmark

getElementById is not a function error

This is driving me nuts. This script executes fine in IE, but in FF I get this error “document.getElementById(buttonID2).fireEvent is not a function”. When I remove the underscores from the submitButton id’s I don’t get any error messages, but then it doesn’t work in IE or FF. Is there a syntax error or is the getElementById not a function supported by FF? Please help.

<script language=”javascript”>
// disable button and submit form
if(document.getElementById(“submitButton2_“)){
var buttonId2=document.getElementById(“submitButton2_
“).title;
document.getElementById(buttonId2).fireEvent(“onclick”);
}

if(document.getElementById(“submitButton1_“)){
var buttonId2=document.getElementById(“submitButton1_
“).title;
document.getElementById(buttonId2).fireEvent(“onclick”);

}

</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 14.2008 — fireEvent only works in IE. See dispatchEvent for FF

Are you referencing element [I]name[/I] or [I]id[/I]? There is a difference.
Copy linkTweet thisAlerts:
@JRyeauthorNov 14.2008 — I assume it's referencing a ID. It's prob. the fireEvent. I will look into dispatchEvent. Thanks
Copy linkTweet thisAlerts:
@slaughtersNov 14.2008 — Why not just disable the buttons and submit this way ?
[CODE]<script language="javascript">
// disable button
if(document.getElementById("submitButton2_")) document.getElementById("submitButton2_").disabled = true;
if(document.getElementById("submitButton1_")) document.getElementById("submitButton1_").disabled = true;

// submit form
if(document.getElementById("formIdValue")) document.getElementById("formIdValue").submit();
</script>[/CODE]
×

Success!

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