Reputation: 1547
I'm working on a project with fullcalendar and bootstrap v3 (newest)
I want to use a modalbox bootstrap styled. I want to define my own buttons in the jQuery because that way I can keep all data inside the fullcalender functions.
Part of js
select: function(start, end, allDay) {
$('#selectModal').on('#Create', function (e) {
// do something...
})
},
Bootstrap modal
<!-- Modal box for select -->
<div class="modal fade" id="selectModal" tabindex="-1" role="dialog" aria-labelledby="selectModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label>Medewerker</label>
<select class="form-control" id="selectBoxMedewerker">
<?php foreach($this->users as $user):?>
<option id="<?=$user->webuserId;?>" value="<?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?>"><?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<input type="text" id="description" class="form-control" placeholder="Description">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="Create" class="btn btn-primary">Create</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
The Problem
If I strip out
$('#selectModal').on('#Create', function (e) {
// do something...
})
Everything works fine but when I add it (to check if create is clicked) I get this error in firebug:
SyntaxError: missing : after property id
$('#Create').click(function(){});
What am I doing wrong here ^
Updated Code:
select: function(start, end, allDay) {
$('#selectModal').modal({
$('#selectModal').on('click','#Create', function (e) {alert('something')});
});
},
Working Code
$('#selectModal').modal({
});
$('#selectModal').on('click','#Create', function (e) {alert('something')});
There is still something wrong with the 'updated code'. I put the check on Create click out the modal and it works.
So my goal is reached. Thanks!
Upvotes: 1
Views: 4504
Reputation: 22619
The correct syntax for on() is .on( events [, selector ] [, data ], handler(eventObject) )
where events
is mandatory. Hence specify click
event
$('#selectModal').on('click','#Create', function (e) {
});
Upvotes: 3
Reputation: 71160
Try replacing:
$('#Create').click(function(){});
With:
$('#Create').on('click',function(){
});
Your current statement is being interpreted as an object literal.
Upvotes: 3