SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax, form.submit() as a callback

    Hi,
    I'm checking with Ajax if an email exists in the database. If it does, the user gets a question if he/she wants to remove it. I have made a function that I call addConfirmFeedback(), which takes two arguments, a string, and a callback-function that get's executed if the user presses OK. But when I pass formElement.submit as a callback-function, it doesn't get executed. In my Javascript Console, it says that an exception occured, and that an "illegal operation on wrappednative prototype object" happened. It seems to work in IE6, but not in FF.

    The code is basically:
    Code:
    addConfirmFeedback( 'My feedbackstring?', xGetElementById( 'newslettersignupform' ).submit );
    
    function addConfirmFeedback( str, fnCallback )
    {
    	
    	if( confirm( str ) )
    	{
    		fnCallback();
    	}
    	else
    	{
    		return false;
    	}
    }
    I'm just using confirm() now, will use my own function later.

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, found the problem. Submit() is a method in the element, and can't be taken out of the element by assigning it to a variable. It's still a problem though, since I don't want to just send the element and call submit() in the addConfirmFeedback()-function.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeay, bingo! All I had to do was also send the context-object as a third argument, like this:

    Code:
    var form = xGetElementById( 'newslettersignupform' );
    addConfirmFeedback( 'string?', form.submit, form );
    
    function addConfirmFeedback( str, fnCallback, context )
    {
    	
    	if( confirm( str ) )
    	{
    		if( context ) fnCallback.call( context );
    		else fnCallback();
    	}
    	else
    	{
    		return false;
    	}
    }
    Last edited by wysiwyg; Mar 8, 2007 at 05:32. Reason: Typo


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
  •