admin管理员组文章数量:1432001
I'm not sure what I'm doing wrong, but I've searched in all "passing data to a bootstrap modal" posts, but still can't find the answer.
I have a table with users. In each row there is a "delete user button". When you click on "delete", a modal shows up which the legend: "Are you sure you want to delete?"
I want the username to be displayed in that legend, so I send the username to a JS file but it doesn't show. Nothing appears.
This is the delete button in every row:
<td><a href="#" onclick="callToModal({$frontuser->username});return false;" class="btn mini red-stripe" role="button" >Delete</a></td>
I'm using smarty that's why the parameter looks like this: {$frontuser->username}
Above that code, I have the definition of the modal:
<!-- modal -->
<div id="myModal3" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 id="myModalLabel3"></h3>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cerrar</button>
<button data-dismiss="modal" class="btn blue" id="deleteok">Confirmar</button>
</div>
</div>
<!-- end modal -->
Then my JS file is:
function callToModal(data) {
$("#myModal3 .modal-header h3").html("Eliminar");
$("#myModal3 .modal-body p").html("Are you sure you want to delete: ", data);
$("#myModal3").modal("show");
}
Any help would be much appreciated!
I'm not sure what I'm doing wrong, but I've searched in all "passing data to a bootstrap modal" posts, but still can't find the answer.
I have a table with users. In each row there is a "delete user button". When you click on "delete", a modal shows up which the legend: "Are you sure you want to delete?"
I want the username to be displayed in that legend, so I send the username to a JS file but it doesn't show. Nothing appears.
This is the delete button in every row:
<td><a href="#" onclick="callToModal({$frontuser->username});return false;" class="btn mini red-stripe" role="button" >Delete</a></td>
I'm using smarty that's why the parameter looks like this: {$frontuser->username}
Above that code, I have the definition of the modal:
<!-- modal -->
<div id="myModal3" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 id="myModalLabel3"></h3>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cerrar</button>
<button data-dismiss="modal" class="btn blue" id="deleteok">Confirmar</button>
</div>
</div>
<!-- end modal -->
Then my JS file is:
function callToModal(data) {
$("#myModal3 .modal-header h3").html("Eliminar");
$("#myModal3 .modal-body p").html("Are you sure you want to delete: ", data);
$("#myModal3").modal("show");
}
Any help would be much appreciated!
2 Answers
Reset to default 4Finally after searching about smarty and js sintax, i found what the problem was.
Simply, it needed some ' ' wrapping the parameter.
So the right way of sending a parameter to JS from SMARTY is this:
<td><a href="#" onclick="callToModal('{$frontuser->username}');" class="btn mini red-stripe" role="button" >Eliminar</a></td>
Why do you have the ma in your .html() call? Simple typo maybe?
$("#myModal3 .modal-body p").html("Are you sure you want to delete: ", data);
It looks like "data" is the name ing from the function call in the delete row? Just change the ma to a + to add the name to the string if that's what you're trying to do.
$("#myModal3 .modal-body p").html("Are you sure you want to delete: "+ data);
本文标签: javascriptHow to pass a string to a bootstrap modalStack Overflow
版权声明:本文标题:javascript - How to pass a string to a bootstrap modal? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745456505a2659126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论