Javascript Inside Blog Post/Page

TheMoMan

New member
Sep 5, 2009
65
2
0
Canada
Need help with something - just will not work no matter what.

I've got some javascript on a blog post and page. The visitor enters some information and clicks "calculate" and out spits an answer.

It works fine if I force the user into each field and perform the calculation on the "onfocus" event but will not work when I put the code into a function and the "onclick" event calls the function.

WP reports an error "object expected" - makes no sense to me at all since the code is correct - I've checked for semi-colons etc., and everything is there.

Will do more debugging - but hoping someone might have some thoughts as to why something so simple would fail using the "onclick" event handler.

Thx...
 


...should add that the code works fine outside of the page/post. I have checked case of the two functions. The onClick event looks like this:

Code:
<a href="#" onClick="performCalculations();">
 
the alternative would be to keep href="#" and have 'return false;' right after the javascript command. Depends of course on what browser you are testing. But what jgrim said works. (the other alternative is using a javascript framework such as jquery to capture the event, since those can easily handle the propagation after effect without even bothering to put javascript inline).
 
kblessinggr makes a very good point. Though I feel it better to start small and build up to more advanced techniques. But all in all it's all about preference. JQuery is very powerful and can even perform AJAX task to make your AJAX experience a lot easier. You should definitely check it out.