/    Sign up×
Community /Pin to ProfileBookmark

onClick functions reloads page instead of running the code inside its own brackets

I tried posting a script earlier, but it was too big to be accepted on this forum. Instead I’ll ask a question, and see if I get any answers that I can use to find the problem myself.

I know its always best to post code, but I couldn’t get it small enough without risking cutting out the parts that people need to see to find the problem.

I have 2 js scripts, that are part of a larger ajax script, that run on page load – I’ll call them A and B. They run fine.

I have 2 scripts that I wrote inside function brackets. They run onClick – I’ll call them C and D

A and B run on page load. This places a button inside an html form. That button runs C just fine onClick.

Script C places a button that is supposed to run D onClick.

Script D is written inside function brackets, and is supposed to fire onClick.

The problem is firebug (tab XHR) shows that D does not post anything to the php script it points too. I know that php script works.

Clicking on the button that is supposed to fire script D causes the onload functions, A and B to fire again. D ignores the code written inside its own brackets.

D reloads the page instead.

C does post, and works fine. It looks to me that C is written the same way as D.

I wrote in a “return false” after each button. I’ve also set the open method of the XMLHttpRequest Object to both true and false. Problem still there.

I wrote I object per onload script, so each script can do its own thing.

To my eye, it looks like I’ve written the functions C (works onClick) and D (doesn’t work because it runs the 2 onload functions onClick, instead of what is written inside its own brackets) the same way.

I can’t spot any syntax errors.

Does anyone know of anything that would cause this? I know browsers do their own thing when syntax errors confuse them too much.

Any suggestions of how to use firebug to further diagnose?

Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@bluetopazauthorJun 17.2012 — Resolved by inserting a missing closing </script> tag
×

Success!

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