SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic function

    Given this form declaration:

    <form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="return AIM.submit(this, {'onStart' : startCallback, 'onComplete' : completeCallback})">

    How do I write the onsubmit dynamically? I have:

    var f = document.createElement("form");
    f.action = "upload.php";
    f.method = "post";
    f.enctype = "multipart/form-data";
    f.onsubmit = function () { return AIM.submit(f, {'onStart' : startCallback, 'onComplete' : completeCallback}); };

    But that doesn't work. What am I missing here?

    Thanks,

    JAS

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not sure what you mean by "dynamically".

    If you have this:

    HTML Code:
    <form action="upload.php" method="post" enctype="multipart/form-data" id="upload_form">
      <!-- form stuff -->
    </form>
    Then the javascript can access it like so:
    Code javascript:
    var theForm = document.getElementById('upload_form');
    theForm.onsubmit = function() {
      return AIM.submit(this, {'onStart' : startCallback, 'onComplete' : completeCallback});
    }
    Now you can change whatever you want in the arguments, if that's what you mean.

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't explain very well. I want to create the form at runtime, so I am basically "translating" the HTML version of the form tag into the appropriate javascript. That's easy enough for the "action", "method", and "enctype" properties, but I can't find the appropriate syntax for the onsubmit function.

    In the HTML tag version, the onsubmit declaration uses "this" (to refer to the form in question), in my example javascript, I replaced "this" with "f" (which names the form object I am creating), but the function does not work. I suspect this has to do with the names of the local functions it calls (i.e. 'startCallback' and 'completeCallback') but I don't know how to rewrite those calls appropriately.

    Does that make sense now?

    Thanks

  4. #4
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please ignore my question. The problem was elsewhere. The onsubmit function works fine.

    Sorry for the bother.


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
  •