SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    SitePoint Evangelist Brandon Luhring's Avatar
    Join Date
    Apr 2002
    Location
    IN, USA
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClick Confirm, with .NET troubles

    I've done plenty of functioning confirm scripts in the past, but this one seems to be a bit different...

    I'm developing in .NET, so my form's submit button is created by the framework, not me. .NET automatically controls the submit buttons onClick attribute. So it's not real easy for me to just pop in "return confirm('whatever');" in front of the script that .NET has put in there. (I've read some articles, and it's pretty much a bug in the current version of .NET)

    If you scroll down to the last post on this page and read a post by Mike Moore, it explains a workaround for sharing the onClick attribute with .NET.

    Now, my problem:
    Unlike, Mike's example, I'm wanting to get a confirm, but I don't know how to have JavaScript "listen" for the return without putting it directly into the onClick -- which I can't do.

    This is what I have at the moment (running of the page onload event):

    Code:
    var OldClick;
    
    function window_onload() {
        OldClick = document.forms[0].BackButton.onclick;
        document.forms[0].BackButton.onclick = MyClick;
    }
    
    function MyClick() {
        if (confirm('This will NOT submit any changes you\\'ve made to Customer Information.\nIf there are changes to be saved, click CANCEL and use the "Subit Changes" Button.\nOtherwise, click OK to return to the Ticket.')){
        	if (typeof(OldClick) == 'function') OldClick();
    	}
    	else { 
    		/*   do nothing   */ 
    	}	
    }
    The problem is that it doesn't listen for any return, and executes the function OldClick() everytime...

    I've tried things like this (and many variations), but I guess I don't know what I'm doing, because it doesn't work:

    Code:
    function window_onload() {
        OldClick = document.forms[0].BackButton.onclick;
        document.forms[0].BackButton.onclick = "return MyClick();"
    }
    Can anyone help me with this??

    Thanks!
    Last edited by Brandon Luhring; Nov 19, 2002 at 11:33.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •