Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

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 09-22-2012, 06:31 PM   PM User | #1
d'Anconia
Regular Coder

 
d'Anconia's Avatar
 
Join Date: Jan 2010
Location: Tempe, AZ
Posts: 142
Thanks: 15
Thanked 5 Times in 5 Posts
d'Anconia is an unknown quantity at this point
Updating User Rating - Unexpected Token (Function Call Issue?)

Okay so my problems it that I keep on getting the following error:

Code:
Uncaught SyntaxError: Unexpected token (
I have put the line in question in bold. I have had problems before with defining functions and calling them. Why am I getting this error? I just want to call the newStarRating function at this point with the given parameters. Any help would be appreciated!

Code:
           
    
   U.addEvent(U.$('rating_star_1'), 'mouseover', function(){ newStarRating(1, "yellow_full"); } );
   U.addEvent(U.$('rating_star_2'), 'mouseover', function(){ newStarRating(2, "yellow_full"); } );
   U.addEvent(U.$('rating_star_3'), 'mouseover', function(){ newStarRating(3, "yellow_full"); } );
   U.addEvent(U.$('rating_star_4'), 'mouseover', function(){ newStarRating(4, "yellow_full"); } );
   U.addEvent(U.$('rating_star_5'), 'mouseover', function(){ newStarRating(5, "yellow_full"); } );
   U.addEvent(U.$('rating_star_6'), 'mouseover', function(){ newStarRating(6, "yellow_full"); } );
   U.addEvent(U.$('rating_star_7'), 'mouseover', function(){ newStarRating(7, "yellow_full"); } );
   U.addEvent(U.$('rating_star_8'), 'mouseover', function(){ newStarRating(8, "yellow_full"); } );
   U.addEvent(U.$('rating_star_9'), 'mouseover', function(){ newStarRating(9, "yellow_full"); } );
   U.addEvent(U.$('rating_star_10'), 'mouseover', function(){ newStarRating(10, "yellow_full"); } );
   <?php 
        
   if (mysqli_num_rows($already_reviewed_query_result) == 1) {
            echo "U.addEvent(U.$('star_rating_div'), 'mouseout', function(){ newStarRating(" . $current_user_review_rows['review_score'] .", 'blue'); } );";
        }
        else {
            echo "U.addEvent(U.$('star_rating_div'), 'mouseout', function(){ newStarRating(0, 'yellow_full'); } );";
            echo "/* \$already_reviewed_query is:*" . $already_reviewed_query . "*/";
        }
        mysqli_close($dbc);
    ?>
 
 



function newStarRating(starNumber, color) {
        'use strict';
        var i = null;
        for (var i = 1; i <= 10; i++) {
           document.getElementById('rating_star_' + i).src='../images/white_star_17px.png';
        } //end of star color reset
        
        var j = null;
        for (var j = 1; j <= starNumber; j++) {
            
            document.getElementById('rating_star_' + j).src='../images/' + color + '_star_17px.png';
            
        }
        
    }

function starSubmitFxn(starNumber) {
    'use strict';
    
    //Get a reference (get element by ID) to the entered username value:
    var ajax = getXMLHttpRequestObject();
    
    
    var currentUsername = '<?php echo $current_username ?>';
    var currentEntityId = '<?php echo $entity_id ?>';
    

                ajax.onreadystatechange = function() {
                    if (ajax.readyState == 4){
                        //Check the status code:
                        if ( (ajax.status >= 200 && ajax.status < 300) || (ajax.status == 304) ) {
                            for ( var r = 1; r <= 10; r++){
                                if (ajax.responseText == r) {
                                    newStarRating(r, "blue");//end of newStarRating call
                                    } //end of response text check
                                } //end of loop
                        
                            } //end of Ajax connectivity check
                        } //end of Ajax ready state
                    }; //end of function for execution on ready state change
                    
                var data = 'currentUsername=' + encodeURIComponent(currentUsername) + '&currentEntityId =' + encodeURIComponent(currentEntityId)
                            + '&starNumber =' encoreURIComponent(starNumber);
                ajax.open('POST', 'resources/star_submit.php?' + data, true);
                ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                ajax.send(data);
    }//End of verifyUsername() function
__________________
Powerful ideas for all lovers of personal and political freedom:
Freedomain Radio
Free Talk Live
d'Anconia is offline   Reply With Quote
Old 09-27-2012, 03:07 AM   PM User | #2
d'Anconia
Regular Coder

 
d'Anconia's Avatar
 
Join Date: Jan 2010
Location: Tempe, AZ
Posts: 142
Thanks: 15
Thanked 5 Times in 5 Posts
d'Anconia is an unknown quantity at this point
Found two of the problems. First of all one of my encodeURIComponent functions is misspelled encoreURIComponent, and I am missing the concatenation operator on that last encodeURIComponent.There still seems to be some other issues so I'm digging in deeper for that. (JSLint / JSHint have been a help and I will utilize them in the future.)

I can't seem to get the event for 'onclick' to initiate the AJAX request. Does the element have to be a link or something in order for an 'onclick' to be triggered or something?
__________________
Powerful ideas for all lovers of personal and political freedom:
Freedomain Radio
Free Talk Live
d'Anconia is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, submitting rating, unexpected token

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 09:04 AM.


Advertisement
Log in to turn off these ads.