jquery - Stop redirection of anchor when clicked in asp.net using javascript -


i want avoid redirection of link if javascript function returns false.

javascript function executed when link clicked(it checks if flag set or not):

function checkflag() {             alert("in check flag");             var href = $(this).attr('href');             var var1;              var flag = '<%=session["hdnflagind"]%>';             alert("flag : "+flag);             if (flag == "1") {                 $.confirm({                     'title': 'confirmation',                     'message': 'do want leave screen without saving work?',                     'buttons': {                         'yes': {                             'class': 'blue',                             'action': function () {                                 alert("yes clicked");                                 '<%session["hdnflagind"]="";%>'                                 return true;                             }                         },                         'no': {                             'class': 'gray',                             'action': function () {                                 alert("no clicked");                                 return false;                             }                         }                     }                 });             }                                 }        

link inside aspx file:

<li><a id="link_individual2" runat="server"                          href="~/views/individuals/individual.aspx" onclick="return checkflag();">individual</a></li> 

the above code not working me please me out.!

try (remove inline javascript)

$(function() {   $("#link_individual2").on("click",function(e) {   e.preventdefault(); // stop link , handle in dialog   var href = this.href;   var flag = '<%=session["hdnflagind"]%>';   if (flag == "1") {     // place preventdefault here if want handle click if flag 1     $.confirm({         'title': 'confirmation',             'message': 'do want leave screen without saving work?',             'buttons': {             'yes': {                 'class': 'blue',                     'action': function () {                     alert("yes clicked");                     '<%session["hdnflagind"]="";%>'                     location = href;                 }             },                 'no': {                 'class': 'gray',                     'action': function () {                     alert("no clicked");                 }             }         }       });     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -