-   Programming (
-   -   JavaScript function disappears after getting called for once (

mohtasham1983 01-15-2008 08:24 AM

JavaScript function disappears after getting called for once

I have 15 html anchor elements in my page with the following handler:


Each of the anchor elements are used for rating the corresponding news. So I passed "this" to the vote function so that it rates the proper news. The vote function uses YUI library to send an asynchronous request to the server and get the result of the page without reloading it (AJAX). So far everything is fine, but after calling vote function once, when I call it using another anchor element, firebug gives me an error that vote is not a function. I don't know why I cannot access it after calling it for once.

If I reload the page, I can call vote function again for once. But I don't want to reload the entire page for every simple request I send to the server and that's why I am interested in using AJAX.

I'm not very familiar with JavaScript tricks, I bet there is a trick to handle this situation.

Thanks in advance.

mohtasham1983 01-15-2008 08:31 AM

It was kinda funny, but after renaming the vote function to vote_news, I got everything working. I think there was another element in the page called "vote" which prevented the vote function to be called.

I hope this post can help somebody.

All times are GMT -5. The time now is 07:01 AM.