Return confirm cancel button not working












0















I have this link in twig :



<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" 
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">


The HTML in the source :



<a href="/app_dev.php/projects/delete/1" class="tip" 
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">

<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`


the onlick confirm cancel button doesn't cancel the action but just keeps going.
Somebody knows what's wrong with this return confirm ?










share|improve this question

























  • You have to show the result html, not template

    – hindmost
    Aug 19 '14 at 14:31











  • Add this into the question

    – hindmost
    Aug 19 '14 at 14:36











  • Done, any ideas on this ?

    – Tommie
    Aug 19 '14 at 14:38











  • any javascript errors in the console?

    – reafle
    Aug 19 '14 at 14:40











  • Why you place button inside a element?

    – hindmost
    Aug 19 '14 at 14:41
















0















I have this link in twig :



<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" 
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">


The HTML in the source :



<a href="/app_dev.php/projects/delete/1" class="tip" 
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">

<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`


the onlick confirm cancel button doesn't cancel the action but just keeps going.
Somebody knows what's wrong with this return confirm ?










share|improve this question

























  • You have to show the result html, not template

    – hindmost
    Aug 19 '14 at 14:31











  • Add this into the question

    – hindmost
    Aug 19 '14 at 14:36











  • Done, any ideas on this ?

    – Tommie
    Aug 19 '14 at 14:38











  • any javascript errors in the console?

    – reafle
    Aug 19 '14 at 14:40











  • Why you place button inside a element?

    – hindmost
    Aug 19 '14 at 14:41














0












0








0








I have this link in twig :



<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" 
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">


The HTML in the source :



<a href="/app_dev.php/projects/delete/1" class="tip" 
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">

<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`


the onlick confirm cancel button doesn't cancel the action but just keeps going.
Somebody knows what's wrong with this return confirm ?










share|improve this question
















I have this link in twig :



<a href="{{ path('relation-delete', {'id': c.getCustomerId}) }}" 
onclick="return confirm('{% trans %}relation.delete{% endtrans %}');"
class="tip" data-original-title="Verwijder klant {{ c.getCustomerName }}">


The HTML in the source :



<a href="/app_dev.php/projects/delete/1" class="tip" 
data-original-title="Verwijder project Lantaarn plaatsen"
onclick="return confirm('Verwijderen');">

<button class="btn btn-danger"><i class="fa fa-times fa-fw"></i></button></a>`


the onlick confirm cancel button doesn't cancel the action but just keeps going.
Somebody knows what's wrong with this return confirm ?







javascript php html symfony twig






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 19 '14 at 17:48









blackbishop

3,54313047




3,54313047










asked Aug 19 '14 at 14:28









TommieTommie

108212




108212













  • You have to show the result html, not template

    – hindmost
    Aug 19 '14 at 14:31











  • Add this into the question

    – hindmost
    Aug 19 '14 at 14:36











  • Done, any ideas on this ?

    – Tommie
    Aug 19 '14 at 14:38











  • any javascript errors in the console?

    – reafle
    Aug 19 '14 at 14:40











  • Why you place button inside a element?

    – hindmost
    Aug 19 '14 at 14:41



















  • You have to show the result html, not template

    – hindmost
    Aug 19 '14 at 14:31











  • Add this into the question

    – hindmost
    Aug 19 '14 at 14:36











  • Done, any ideas on this ?

    – Tommie
    Aug 19 '14 at 14:38











  • any javascript errors in the console?

    – reafle
    Aug 19 '14 at 14:40











  • Why you place button inside a element?

    – hindmost
    Aug 19 '14 at 14:41

















You have to show the result html, not template

– hindmost
Aug 19 '14 at 14:31





You have to show the result html, not template

– hindmost
Aug 19 '14 at 14:31













Add this into the question

– hindmost
Aug 19 '14 at 14:36





Add this into the question

– hindmost
Aug 19 '14 at 14:36













Done, any ideas on this ?

– Tommie
Aug 19 '14 at 14:38





Done, any ideas on this ?

– Tommie
Aug 19 '14 at 14:38













any javascript errors in the console?

– reafle
Aug 19 '14 at 14:40





any javascript errors in the console?

– reafle
Aug 19 '14 at 14:40













Why you place button inside a element?

– hindmost
Aug 19 '14 at 14:41





Why you place button inside a element?

– hindmost
Aug 19 '14 at 14:41












2 Answers
2






active

oldest

votes


















4














You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:



<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}





share|improve this answer
























  • It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

    – Tommie
    Aug 21 '14 at 14:52





















0














Adding event.preventDefault(); fixed it.



Here is an example:



console.log('Validating...');

function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}





share|improve this answer
























  • or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

    – Dhruv
    Nov 24 '18 at 23:02











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',
autoActivateHeartbeat: false,
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%2f25386032%2freturn-confirm-cancel-button-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:



<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}





share|improve this answer
























  • It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

    – Tommie
    Aug 21 '14 at 14:52


















4














You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:



<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}





share|improve this answer
























  • It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

    – Tommie
    Aug 21 '14 at 14:52
















4












4








4







You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:



<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}





share|improve this answer













You can validade the confirm box outside of html element, in a function and, call this function on 'onclick' event. Like this:



<a href="somePage" onclick="return myFunction()">My link</a>

function myFunction() {
if (confirm("Confirm message")) {
// do stuff
} else {
return false;
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 19 '14 at 17:40









Helam.DevHelam.Dev

562




562













  • It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

    – Tommie
    Aug 21 '14 at 14:52





















  • It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

    – Tommie
    Aug 21 '14 at 14:52



















It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

– Tommie
Aug 21 '14 at 14:52







It turns out this was causing the problem in a other javascript file: $("a").click(function(e) { e.preventDefault(); location.href = $(this).attr("href"); });

– Tommie
Aug 21 '14 at 14:52















0














Adding event.preventDefault(); fixed it.



Here is an example:



console.log('Validating...');

function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}





share|improve this answer
























  • or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

    – Dhruv
    Nov 24 '18 at 23:02
















0














Adding event.preventDefault(); fixed it.



Here is an example:



console.log('Validating...');

function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}





share|improve this answer
























  • or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

    – Dhruv
    Nov 24 '18 at 23:02














0












0








0







Adding event.preventDefault(); fixed it.



Here is an example:



console.log('Validating...');

function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}





share|improve this answer













Adding event.preventDefault(); fixed it.



Here is an example:



console.log('Validating...');

function confirm_delete(){
var txt;
var r = confirm("Are you sure you want to delete?");
if (r == true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
event.preventDefault();
}
console.log(txt);
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 23:01









DhruvDhruv

314




314













  • or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

    – Dhruv
    Nov 24 '18 at 23:02



















  • or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

    – Dhruv
    Nov 24 '18 at 23:02

















or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

– Dhruv
Nov 24 '18 at 23:02





or that "return false;" statement would do the trick to I suppose, I missed it when I was reading it first...

– Dhruv
Nov 24 '18 at 23:02


















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25386032%2freturn-confirm-cancel-button-not-working%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

Costa Masnaga

Fotorealismo

Sidney Franklin