I am trying to submit a form via ajax from inside a colorbox, but when I submit the form is tells me that the function is not available. Need help to understand
/* Inside colorbox */
<div id="messageform" style="display:none;">
<?php echo Form::open(); ?>
<?php echo Form::label('message', 'message'); ?> <br />
<?php echo Form::textarea('message', NULL,array('id'=>'messagecontent')); ?> <br />
<button id="sendmessage" onclick="sendmessage('<?= Auth::instance()->get_user(); ?>', '<?= $user->id; ?>', 'test message');">Send</button>
<?php echo Form::close(); ?>
</div>
/* AJAX function located before body close*/
function sendmessage(user_id, to_id, message)
{
var loadUrl= '<?=url::base()?>message/send';
$.post(loadUrl,{uid: user_id, tid: to_id, message: message}, function(code){});
}
I am getting a ‘sendmessage’ not found from the console
/* open colorbox */
The colorbox is being launched via link click
$('.openmessagelink').click(function(){
$.colorbox({inline:true, width:"50%", open:true, href:"#messageform",
onClosed: function() {
$('#messageform').hide();
},
onOpen: function() {
$('#messageform').show();
}
});
});
Your function has the same name as the butrón id.