Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2011, 08:12 PM   PM User | #1
natedhill
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
natedhill is an unknown quantity at this point
checking the database

Hi,

I'm a front end developer/designer who has been thrust into the position of some backend developing. I'm in a bit of a time crunch and could use some help/direction/input on some code.

I'm working on a photo contest site and I need the votes for an image to cost a credit. The voting and credits are all set up, I just need the voting to check the database to see if the logged in user has credits to vote, if so, then reduce their credits by 1 and complete the vote.

Here is the voting code:
Code:
window.addEvent('domready', function() {
	$$('#jwajaxvote-inline-rating a').each(function(el) {
		el.addEvent('click', function(e) {

			
			e = new Event(e).stop();

			
			if (jwallpapers_is_user_voting) {
				
				alert(jwallpapers_userAlreadyVotedMessage);
				return;
			} else {
				
				
				
				jwallpapers_is_user_voting = true;
			}

			
			if (jwallpapers_isUserVoteAllowed == false) {
				alert(jwallpapers_isUserVoteAllowedMessage);
				return false;
			}

			
			
			if (jwallpapers_userAlreadyVoted == true) {
				alert(jwallpapers_userAlreadyVotedMessage);
				return false;
			}

			var id = this.getAttribute('id');

			var url = eval("jwallpapers_rating_link_" + id);

			var div1 = $('rating_stars_update');
			var div2 = $('jwajaxvote').empty();
			div2.innerHTML = '<img src="' + jwallpapers_joomla_base_url + 'components/' + jwallpapers_option + '/images/ajax_loader/ajax-loader-rating.gif" border="0" align="absmiddle" />';
			var div3 = $('rating_verbose_update');

			
			
			
			new Ajax(url, {
				method : 'get',
				onComplete : function(response, responseXML) {

					jwallpapers_userAlreadyVoted = true;

					
					var root = responseXML.documentElement;
					var rating_stars_update = root.getElementsByTagName('rating_stars_update').item(0);
					var rating_count_update = root.getElementsByTagName('rating_count_update').item(0);
					var rating_verbose_update = root.getElementsByTagName('rating_verbose_update').item(0);

					
					var updateRating = rating_stars_update.firstChild.nodeValue;
					var updateCounter = rating_count_update.firstChild.nodeValue;
					var updateVerbose = rating_verbose_update.firstChild.nodeValue;

					
					div1.empty().setHTML(updateRating);
					div2.empty().setHTML(updateCounter);
					div3.empty().setHTML(updateVerbose);

					
					jwallpapers_is_user_voting = false;

				}
			}).request();
		});
	});
});
I should note this is not my code. I've never done any javascript/ajax coding before. My programmer had done this on a previous version of the site, but he quit and then the site went all haywire and I had to reinstall components which erased what he had done.

Thanks.
natedhill is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 AM.


Advertisement
Log in to turn off these ads.