Like I said before: create a hidden field and let jQuery assign a value to it before the AJAX call is done.
Next to the span element, create a hidden input:
Code:
<input type="hidden" name="message_count" id="message_count" value="0" />
Also, adjust your jQuery script that responds to keyup in the message textarea:
Code:
$('#body').keyup(function(){
var chars = this.value.length,
messages = Math.ceil(chars / 160),
remaining = messages * 160 - (chars % (messages * 160) || messages * 160);
$remaining.text(remaining + ' characters remaining');
$messages.text(messages + ' page(s)');
$('#message_count').val(messages); //this line is new!
});
Now, remember that the POST value for the controller is message_count, not messages.