p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5 (http://p2p.wrox.com/forumdisplay.php?f=340)
-   -   return value of Confirm in javascript not Working onClientClick (http://p2p.wrox.com/showthread.php?t=71884)

sim December 18th, 2008 04:54 AM

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"/>


Old Pedant December 18th, 2008 04:40 PM

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;
}



All times are GMT -4. The time now is 11:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.