Does the html look correct for the select when viewing the rendered page's source? You should post the checkRegistrationExist() function too.
Apr 29, 2018
6
Level 1
How can I pass a PHP variable to an select onChange event
I have a blade page where I sent to it (via controller) a 'Class' object (its literally a class for a school application). I have a select where onChange I need it to check it registration exisit already...
<div class="form-group">
{{Form::label('forRegMember', "Select The Member That This Registration Is For")}}
{{Form::select('forRegMember', $memberList, null, ['class'=>'form-control', 'placeholder' => 'Select Member...', 'onchange' => 'checkRegistrationExist(this.value, ' . $class->SFLClassID . ')' ])}}
</div>
The page Renders, but the checkRegistrationExist function doesn't fire and I get this error in the console...
Uncaught SyntaxError: Invalid or unexpected token
Whats the best way to handle this in Laravel.
Again, forgive the newbish nature of this question. I'm literally just getting started with Laravel. (Love it though thus far)
Level 67
Try changing the select to this:
{{Form::select('forRegMember', $memberList, null, [
'class'=>'form-control',
'placeholder' => 'Select Member...',
'id' => 'reg-member-select',
'data-classid' => $class->SFLClassID
]) }}
and this js
$(function() {
$('#reg-member-select').on('change', function(e) {
let memberID = this.value;
let classID = $(this).data('classid');
$.ajax({
url:'/api/checkIfRegistrionExisit/member/'+memberID+'/classid/'+classID,
type: 'GET',
dataType: "json",
success:function(msg){
if(msg.length > 0){
$('#forRegMember').val('');
alert("This Member Is Already Registered For This Class. Please Select Another Member Of Your Group You Wish To Register.");
}
else
{
alert('Not Registered...');
}
}
});
});
});
Please or to participate in this conversation.