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 Answers 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
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
pita
which function should be called in the button onclick? how can i stop button submit when user click cancel?
Imdad
I'm not getting you. What gets submitted?
pita
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?
Imdad
I'm adding another answer as it would not be readable here in comment
lang-js
return test
in the test function???