views:

142

answers:

2

This is the jQuery, both the game_id and the $(this).val() are integers

    /* AJAX call: save to DB input name=#game_id# value=#game_rating */
    $.post("game_rating_submit.cfm", {
        id: game_id,
        rating: $(this).val()
     }, 
     function(data) {
        alert('data: ' + data);
    });

This is the coldfusion part that's failing:

<cfif NOT IsNumeric("form.rating")>
    <cfset variables.error = 'Invalid rating value #form.rating#.' >
</cfif>
<cfoutput>#variables.error#</cfoutput>

For some reason form.rating is not numeric?

+1  A: 

I think rating: $(this).val() is referring to the wrong DOM element. Pull that reference outside the .post method, like so.

var rating = $('#my_rating_elem').val();
$.post('game_rating_submit.cfm', { id: game_id, rating: rating}) ...

Or make sure that $(this) is referring to the object you expect by assigning it to another local variable

var klass = $(this); $.post('game_rating_submit.cfm', { id: game_id, rating: klass.val()}) ...

This is necessary because in the context of the .post() method the $(this) is NOT referring to the object you were expecting (which is the $(this) outside the .post())

Cody Caughlan
Ah, thanks, this is true
davidosomething
+4  A: 

When quoted "form.rating" is the string "form.rating", if you want the value try...

 <cfif NOT IsNumeric(form.rating)>
     <cfset variables.error = 'Invalid rating value #form.rating#.' >
 </cfif>
 <cfoutput>#variables.error#</cfoutput>
kevink