You are currently viewing the BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
return value of Confirm in javascript not Working onClientClick
return value of Confirm in javascript not Working OnClientClick of button.
button is placed in updatePanel (AJAX).
JavaScript code for confirm is also in updatePanel(AJAX)
Code:
function chkleave()
{
var dat1 = document.getElementById("txttxtleavestartdate").value;
if (dat1.length != 10)
{
returntrue;
}
var dat2 = document.getElementById("txttxtleaveenddate").value;
if (dat2.length != 10)
{
returntrue;
}
if(Math.floor((new Date(dat2)-new
Date(dat1))/(1000*60*60*24))>document.getElementById("lblpendingleaves").innerHTML)
{
if (!confirm("Your Leave days are exceeding pending leaves. \n Your extra leaves will be considered 'Leave Without Pay'. \n Are you sure you want to send it for approval."))
return false;
}
}
<asp:ButtonID="btnSubmit"OnClientClick="return chkleave()"ValidationGroup="vali"CssClass="txtBox"BackColor="#1B3091"Font-Bold="True"ForeColor="White"runat="server"Text="Submit"OnClick="btnSubmit_Click"/>
Last edited by sim : December 19th, 2008 at 02:26 AM.
Reason: made changes after response but still not working
You are missing a space between return and false so you are always getting a JavaScript error
and since apparently you don't have JavaScript debugging turned on you can't see that error.
The result is that the JavaScript code is effectively ignored.
You also do *NOT* do
return true;
when the confirm is true or the confirm is not invoked, so you can't even predict what will happen.
Yes, generally if you omit a return value from a JS function the result is the same as if you
returned true, but you can *NOT* guarantee that. If the function should return a value,
make sure that it ALWAYS does so, no matter what.
Your code should end with
Code:
return true;
}
Last edited by Old Pedant : December 18th, 2008 at 04:43 PM.