I want to pass a variable to some javascript in a Bootstrap Widget. I am using bootstrap.widgets.TbButton and I want to render a modal and pass a variable to a url. The data I want is $data->id and with a normal button I would just use
However I am using the bootstrap.widgets.TbButton widget and I want to render a modal then go to a url - I am unsure how to get the ‘id’ passed into the javascript - I have
$this->widget('bootstrap.widgets.TbButton', array(
'label'=>'Confirm Modal',
'type'=>'warning',
'htmlOptions'=>array(
'onclick'=>'js:bootbox.confirm("Are you sure?",
function(confirmed){
if (confirmed) {
window.location.href="index.php?r=newtask/complete&id="
}
})'
Thanks for your response - I did try this however I get in the console "Uncaught Syntax Error:Unexpected Number" however I cannot see what is causing this. It does according to the source generate the url as I want however due to the syntax error the modal will not display. According to the console it is on line 84 however that is just <div> and nothing else. The page source from the console is
<a onclick="js:bootbox.confirm("Are you sure?",
function(confirmed){
if (confirmed) {
window.location.href="index.php?r=newtask/complete&id="4
}
})" id="yw1" class="btn btn-warning">Confirm Import File</a>
</div>
Uncaught SyntaxError: Unexpected number
</div>
If I remove $data->id the error is resolved however the url is not correctly formed. I would appreciate any help as to how to write the javascript correctly with the widget.