Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5
| Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 AJAX by Matt Gibbs, Dan Wahlin; ISBN: 9780470109625
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 18th, 2008, 04:54 AM
sim sim is offline
Registered User
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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)

function chkleave()
var dat1 = document.getElementById("txttxtleavestartdate").value;
if (dat1.length != 10) 
var dat2 = document.getElementById("txttxtleaveenddate").value;
if (dat2.length != 10) 
if(Math.floor((new Date(dat2)-new
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
  #2 (permalink)  
Old December 18th, 2008, 04:40 PM
Friend of Wrox
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

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
    return true;

Last edited by Old Pedant; December 18th, 2008 at 04:43 PM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Submit Button w/OnClientClick: Not Working kwilliams ASP.NET 2.0 Professional 4 August 25th, 2008 12:00 PM
JavaScript Confirm Box ricespn Classic ASP Basics 1 January 20th, 2007 12:48 AM
Javascript Confirm Message box itHighway Javascript How-To 5 September 25th, 2006 02:51 AM
Javascript Confirm dialog difficulty ayrton Javascript 1 May 20th, 2005 03:34 AM
need Confirm() with Yes/No buttons in JavaScript ehelpcornet ASP.NET 1.0 and 1.1 Basics 1 June 3rd, 2004 07:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.