how to set bootstrap modal as confirm dialog?











up vote
0
down vote

favorite












how to set bootstrap modal as confirm window i am try this code but it returns true when modal is open.



this code not work it allow to redirect. before show a modal.



bootstrap modal:



<a href="https/www.google.com" id="btn-confirm">Confirm</a>

<div id="deletemodel" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<p>Do you really want to delete these record? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info deleteCancel">Cancel</button>
<button type="button" class="btn btn-danger deleteConfirm">Delete</button>
</div>
</div>
</div>




Script



<script>
var modalConfirm = function(callback){

$("#btn-confirm").on("click", function(){
$("#deletemodel").modal('show');
});
$("#deletemodel .deleteConfirm").on("click", function(){
callback(true);
$("#deletemodel").modal('hide');
});
$("#deletemodel .deleteCancel").on("click", function(){
callback(false);
$("#deletemodel").modal('hide');
});

};
modalConfirm(function(confirm){
if(confirm){
return true;
}else{
return false;
}
});
</script>


anybody can help me to solve this problem?










share|improve this question






















  • You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
    – Cabrra
    Nov 22 at 14:05















up vote
0
down vote

favorite












how to set bootstrap modal as confirm window i am try this code but it returns true when modal is open.



this code not work it allow to redirect. before show a modal.



bootstrap modal:



<a href="https/www.google.com" id="btn-confirm">Confirm</a>

<div id="deletemodel" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<p>Do you really want to delete these record? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info deleteCancel">Cancel</button>
<button type="button" class="btn btn-danger deleteConfirm">Delete</button>
</div>
</div>
</div>




Script



<script>
var modalConfirm = function(callback){

$("#btn-confirm").on("click", function(){
$("#deletemodel").modal('show');
});
$("#deletemodel .deleteConfirm").on("click", function(){
callback(true);
$("#deletemodel").modal('hide');
});
$("#deletemodel .deleteCancel").on("click", function(){
callback(false);
$("#deletemodel").modal('hide');
});

};
modalConfirm(function(confirm){
if(confirm){
return true;
}else{
return false;
}
});
</script>


anybody can help me to solve this problem?










share|improve this question






















  • You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
    – Cabrra
    Nov 22 at 14:05













up vote
0
down vote

favorite









up vote
0
down vote

favorite











how to set bootstrap modal as confirm window i am try this code but it returns true when modal is open.



this code not work it allow to redirect. before show a modal.



bootstrap modal:



<a href="https/www.google.com" id="btn-confirm">Confirm</a>

<div id="deletemodel" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<p>Do you really want to delete these record? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info deleteCancel">Cancel</button>
<button type="button" class="btn btn-danger deleteConfirm">Delete</button>
</div>
</div>
</div>




Script



<script>
var modalConfirm = function(callback){

$("#btn-confirm").on("click", function(){
$("#deletemodel").modal('show');
});
$("#deletemodel .deleteConfirm").on("click", function(){
callback(true);
$("#deletemodel").modal('hide');
});
$("#deletemodel .deleteCancel").on("click", function(){
callback(false);
$("#deletemodel").modal('hide');
});

};
modalConfirm(function(confirm){
if(confirm){
return true;
}else{
return false;
}
});
</script>


anybody can help me to solve this problem?










share|improve this question













how to set bootstrap modal as confirm window i am try this code but it returns true when modal is open.



this code not work it allow to redirect. before show a modal.



bootstrap modal:



<a href="https/www.google.com" id="btn-confirm">Confirm</a>

<div id="deletemodel" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<p>Do you really want to delete these record? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info deleteCancel">Cancel</button>
<button type="button" class="btn btn-danger deleteConfirm">Delete</button>
</div>
</div>
</div>




Script



<script>
var modalConfirm = function(callback){

$("#btn-confirm").on("click", function(){
$("#deletemodel").modal('show');
});
$("#deletemodel .deleteConfirm").on("click", function(){
callback(true);
$("#deletemodel").modal('hide');
});
$("#deletemodel .deleteCancel").on("click", function(){
callback(false);
$("#deletemodel").modal('hide');
});

};
modalConfirm(function(confirm){
if(confirm){
return true;
}else{
return false;
}
});
</script>


anybody can help me to solve this problem?







jquery twitter-bootstrap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 13:56









VIJAY

155




155












  • You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
    – Cabrra
    Nov 22 at 14:05


















  • You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
    – Cabrra
    Nov 22 at 14:05
















You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
– Cabrra
Nov 22 at 14:05




You are 90% done. You got the basics but you are missing some pieces. First you can define the modal to reference it whenever you need it (HTML file). Then on your script whenever you need it, you can set the "this.modal = <referenceToYourHTML>". Note that you will need to define the modalView, and the reference. Hope this helps you figuring things out.
– Cabrra
Nov 22 at 14:05












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Just change a couple lines in your JS :



$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});


e is the click event.
preventDefault tells the browser not to follow the HTML default behavior (which usually prepends to the JS behavior).



$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});





share|improve this answer























  • sorry, it works but after click modal deleteConfirm button it will not redirect.
    – VIJAY
    Nov 23 at 7:17










  • Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
    – Jean-Marc Zimmer
    Nov 23 at 7:20













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432561%2fhow-to-set-bootstrap-modal-as-confirm-dialog%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Just change a couple lines in your JS :



$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});


e is the click event.
preventDefault tells the browser not to follow the HTML default behavior (which usually prepends to the JS behavior).



$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});





share|improve this answer























  • sorry, it works but after click modal deleteConfirm button it will not redirect.
    – VIJAY
    Nov 23 at 7:17










  • Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
    – Jean-Marc Zimmer
    Nov 23 at 7:20

















up vote
0
down vote













Just change a couple lines in your JS :



$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});


e is the click event.
preventDefault tells the browser not to follow the HTML default behavior (which usually prepends to the JS behavior).



$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});





share|improve this answer























  • sorry, it works but after click modal deleteConfirm button it will not redirect.
    – VIJAY
    Nov 23 at 7:17










  • Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
    – Jean-Marc Zimmer
    Nov 23 at 7:20















up vote
0
down vote










up vote
0
down vote









Just change a couple lines in your JS :



$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});


e is the click event.
preventDefault tells the browser not to follow the HTML default behavior (which usually prepends to the JS behavior).



$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});





share|improve this answer














Just change a couple lines in your JS :



$('#btn-confirm').on('click', function(e) {
e.preventDefault();// <--- This line.
$('#deletemodel').modal('show');
});


e is the click event.
preventDefault tells the browser not to follow the HTML default behavior (which usually prepends to the JS behavior).



$('#deletemodel .deleteCancel').on('click', function() {
location.href = 'https://google.com'
});






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 at 7:21

























answered Nov 22 at 15:51









Jean-Marc Zimmer

36914




36914












  • sorry, it works but after click modal deleteConfirm button it will not redirect.
    – VIJAY
    Nov 23 at 7:17










  • Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
    – Jean-Marc Zimmer
    Nov 23 at 7:20




















  • sorry, it works but after click modal deleteConfirm button it will not redirect.
    – VIJAY
    Nov 23 at 7:17










  • Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
    – Jean-Marc Zimmer
    Nov 23 at 7:20


















sorry, it works but after click modal deleteConfirm button it will not redirect.
– VIJAY
Nov 23 at 7:17




sorry, it works but after click modal deleteConfirm button it will not redirect.
– VIJAY
Nov 23 at 7:17












Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
– Jean-Marc Zimmer
Nov 23 at 7:20






Oh, yeah, you have to manually redirect using location.href = "https://google.com". Editing the answer... Done.
– Jean-Marc Zimmer
Nov 23 at 7:20




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432561%2fhow-to-set-bootstrap-modal-as-confirm-dialog%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo