Link to home
Create AccountLog in
Avatar of JT_SIRO
JT_SIRO

asked on

Javascript confirm - How do I run more javascript when Yes is clicked

I have a button that calls some javascript that calls a method of my datagrid.  I want to wrap it in a confirm button but this doesn't work:

function confirmation() {
      var answer = confirm("Are you sure you want to delete this stem?")
      if (answer){
          alert('asdf');
        gvCurrentStems.delete_record(this); return false;      
      }
}

I think it's because the code is outside of the grid itself.  This what I had in the OnClienkClick event, which worked fine: "gvCurrentStems.delete_record(this); return false'"

Is there a way to put all the logic in one line in the OnClickEvent?



Avatar of numberkruncher
numberkruncher
Flag of United Kingdom of Great Britain and Northern Ireland image

Your function needs to be defined in either a script block or an external .js file.

Then in your OnClientClick event use:

return confirmation();
Avatar of JT_SIRO
JT_SIRO

ASKER

I did that.  The problem is it's not recognizing the grid gvCurrentStems in this line:
gvCurrentStems.delete_record(this); return false;    
Sorry, I should have seen that:
function confirmation(grid) {
      var answer = confirm("Are you sure you want to delete this stem?")
      if (answer){
          alert('asdf');
        gvCurrentStems.delete_record(grid); return false;      
      }
}



return confirmation(this);

Open in new window

Avatar of JT_SIRO

ASKER

Thanks!  That did it.  It seems to be posting back to the server when I click cancel on the confirm dialog.  Is there a way around that?  Not a huge deal, but unnecessary.
ASKER CERTIFIED SOLUTION
Avatar of numberkruncher
numberkruncher
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JT_SIRO

ASKER

You the man!  Thanks
Glad that I could be of help!

Happy New Year!!