Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder d'Anconia's Avatar
    Join Date
    Jan 2010
    Location
    Tempe, AZ
    Posts
    149
    Thanks
    16
    Thanked 6 Times in 6 Posts

    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
    Datagonia Web (My Portfolio)

    Powerful ideas for all lovers of personal and political freedom:
    Freedomain Radio
    Free Talk Live

  • #2
    Regular Coder d'Anconia's Avatar
    Join Date
    Jan 2010
    Location
    Tempe, AZ
    Posts
    149
    Thanks
    16
    Thanked 6 Times in 6 Posts
    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?
    Datagonia Web (My Portfolio)

    Powerful ideas for all lovers of personal and political freedom:
    Freedomain Radio
    Free Talk Live


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •