SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Is this $(document).delegate code written correctly?

    I have this code just before my </body> tag:

    <script type="text/Javascript">

    Code:
    $(document).delegate("textarea,select,input[type='text']","change",
    function() { persistData($(this)); 
    }
    );
    
    </script>
    It is supposed to execute the persistData() function, which saves the data typed into the fields. Can you tell me if this is written correctly? The code is not saving the data presently. The page correctly links to the external js page that executes this function.

    Purpose for this script: I want to avoid as many buttons as possible in this iPhone app page, and I thought this would get rid of yet another button with an onClick function.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    Can you tell me if this is written correctly? The code is not saving the data presently. The page correctly links to the external js page that executes this function.

    Purpose for this script: I want to avoid as many buttons as possible in this iPhone app page, and I thought this would get rid of yet another button with an onClick function.
    The code seems to work on a web browser, but as for developing for the iPhone I have no way to confirm or not.

    Perhaps someone in our Developing for Mobile Devices forum might be able to shed some more light on this.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The following link may help you http://stackoverflow.com/a/8238550/1118556

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Paul. I'm not getting any errors in Chrome for this, so the problem must be elsewhere. (I'm not getting ANY errors, so that's a real problem!)

    Thanks, Chris, but I don't see your link's relevance to my case.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StevenHu View Post
    Thanks, Paul. I'm not getting any errors in Chrome for this, so the problem must be elsewhere. (I'm not getting ANY errors, so that's a real problem!)

    Thanks, Chris, but I don't see your link's relevance to my case.
    It may be worth noting though that as of jQuery 1.7, .delegate() has been superceded by .on()

    For example:

    Code javascript:
    $(document).on("change", "textarea,select,input[type='text']", function() {
        persistData($(this)); 
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •