1

I am using a jquery dialog, and what i want to implement is when user press "ok", the progamming keep going, when press "cancel", it stoped.

 function displaymessage()
{
 $("#confirm").dialog({ 
 buttons:{
 "OK":function(){$(this).dialog("close"); test(1);},
 "Cancel":function(){$(this).dialog("close");test(0);} 
 }
 }); 
function test(bool)
{
if(bool==1)
return true;
else return false;
}
return test();
}
<div id="confirm"></div>
<input type="button" value="Click me!" onclick="return displaymessage()" />

But how to control the function test run after user click "ok" button?

thanks

​​​​​

asked May 11, 2012 at 13:36
2
  • why do you have an extra return test in the test function??? Commented May 11, 2012 at 13:46
  • @rutwikreddy give the test() value to displaymeesage(), so in the onclick event, if it is false, the button will stop submit. that is what i am thinking, but it doesn't work Commented May 11, 2012 at 14:14

2 Answers 2

2

Take 2 buttons

<asp:button id="submit" onclientclick="return displaymessage()" />
<asp:button id="submit_hidden" onclick="submit_OnClick" runat="server"/>

Hide the button with id submit_hidden. (may be via css dsiplay:none;)

And in jquery change the code

$("#confirm").dialog({
 autoOpen:false, 
 buttons:{
 "OK":function(){ $("#submit_hidden").click();
 $(this).dialog("close"); },
 "Cancel":function(){ $(this).dialog("close");} 
 }
 }); 

Now you don't need to return anything.

answered May 14, 2012 at 12:28

2 Comments

Thank you very much, this two buttons idea do solve my problem and i modified the code from click() to trigger(). thanks
May I know the reason of negative voting?
1
function displaymessage()
{
 $("#confirm").dialog({
 autoOpen:false, 
 buttons:{
 "OK":function(){ test(1); $(this).dialog("close"); },
 "Cancel":function(){ test(0); $(this).dialog("close");} 
 }
 }); 
}
function test(bool)
{
 if(bool==1)
 return true;
 else 
 return false;
}
answered May 11, 2012 at 13:41

4 Comments

which function should be called in the button onclick? how can i stop button submit when user click cancel?
I'm not getting you. What gets submitted?
it's actually an <asp:button id="submit" onclick="submit_OnClick" onclientclick="return displaymessage()" runat="server"/> if the displaymessage() return false, it won't run "submit_OnClick" which is the code on the server side. So how can I give the bool value to "displaymessage()" function?
I'm adding another answer as it would not be readable here in comment

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.