viewing the form variables that are being submitted

Discussion in 'Javascript' started by yawnmoth, May 1, 2009.

  1. yawnmoth

    yawnmoth Guest

    <form action="">
    <input type="submit" name="a" value="Submit">
    <input type="submit" name="b" value="Save">
    </form>

    <script>
    function zzz() {
    var vars = '', e = this.elements;
    for (i=0;i<e.length;i++)
    vars+= e.name + '=' + e.value + '&';
    alert(vars);
    }

    for(i=0;f=document.forms;i++)
    f.onsubmit=zzz;
    </script>

    If you hit either submit button you'll get an alert box with
    "a=Submit&b=Save&" in it. The resultant URL, however, will only have
    one of them set. ie. "b=Save" or "a=Submit" but not both.

    My question is... is it possible, in javascript, to view not what
    form elements exist but what form variables will be submitted?

    My goal is to adapt this into a bookmarklet that I can use on
    arbitrary websites.
     
    yawnmoth, May 1, 2009
    #1
    1. Advertisements

  2. On Fri, 01 May 2009 12:02:32 -0700, yawnmoth wrote:

    [ Form and code snipped ]
    You might want to try reading this:

    http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/
    e4859563aabaf768/dec455c027d3154c?q=serialize+form&lnk=ol&
     
    Jeremy J Starcher, May 1, 2009
    #2
    1. Advertisements

  3. In any given form, only one input with type submit can be successful.
    Only controls that are successful will be submitted as part of the
    form data.

    http://www.w3.org/TR/html401/interact/forms.html#successful-controls
     
    Justin McConnell, May 1, 2009
    #3
  4. yawnmoth

    SAM Guest

    Le 5/1/09 9:02 PM, yawnmoth a écrit :


    Usually both (or all) submit buttons have same name, and it is the sent
    value that gives the information about which one was clicked.
    I think no.

    Except
    With which navigator ?
     
    SAM, May 2, 2009
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.