order of form elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • groups2@reenie.org

    order of form elements

    I have a form with a dropdown (select) menu a text input field and
    some hidden values, along with an input botton that triggers an ajax
    function that submits the form.
    If the button is after the select statement, the chosen value of the
    selection of the dropdown is posted. But if the button is before the
    select statement, everything in the form is posted but the value of
    the selection

    Why would the select box be left out of the post ?

  • Thomas 'PointedEars' Lahn

    #2
    Re: order of form elements

    groups2@reenie. org wrote:
    I have a form with a dropdown (select) menu a text input field and
    some hidden values, along with an input botton that triggers an ajax
    function that submits the form.
    It would have been wise to post that function.
    If the button is after the select statement,
    There are no statements in the (eXtensible) HyperText *Markup Language*.
    You mean a `select' _element_.
    the chosen value of the selection of the dropdown is posted. But if
    the button is before the select statement, everything in the form is
    posted but the value of the selection
    >
    Why would the select box be left out of the post ?
    As you have not provided enough information, I have to make an educated
    guess: your "ajax function" iterates through the form elements collection
    (where the numeric index of an element is defined by the arrangement of
    the controls in the markup) until it finds the submit button, i.e. an
    element of type "submit". That algorithm should be modified.


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

    Comment

    • groups2@reenie.org

      #3
      Re: order of form elements

      No, but close. I knew where the form iteration occured and when I
      looked at it it was like this:

      var numberElements = frm.elements.le ngth-1;
      for(var i = 0; i < numberElements; i++) {
      queryString+=fr m.elements[i].name
      +"="+encodeURIC omponent(frm.el ements[i].value);
      if(i < numberElements-1) queryString+="& ";
      }

      So for some reason, it was written to always skip the last element. I
      took out the -1 from "length-1" and it works as expected now. Thanks,
      you really helped.


      On Sep 2, 5:20 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
      wrote:
      grou...@reenie. org wrote:
      I have a form with a dropdown (select) menu a text input field and
      some hidden values, along with an input botton that triggers an ajax
      function that submits the form.
      >
      It would have been wise to post that function.
      >
      If the button is after the select statement,
      >
      There are no statements in the (eXtensible) HyperText *Markup Language*.
      You mean a `select' _element_.
      >
      the chosen value of the selection of the dropdown is posted. But if
      the button is before the select statement, everything in the form is
      posted but the value of the selection
      >
      Why would the select box be left out of the post ?
      >
      As you have not provided enough information, I have to make an educated
      guess: your "ajax function" iterates through the form elements collection
      (where the numeric index of an element is defined by the arrangement of
      the controls in the markup) until it finds the submit button, i.e. an
      element of type "submit". That algorithm should be modified.
      >
      PointedEars
      --
      "Use any version of Microsoft Frontpage to create your site. (This won't
      prevent people from viewing your source, but no one will want to steal it.)"
      -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

      Comment

      • RobG

        #4
        Re: order of form elements

        On Sep 3, 8:12 am, grou...@reenie. org wrote:
        No,
        Please don't top post, reply below trimmed quotes.

        but close. I knew where the form iteration occured and when I
        looked at it it was like this:
        >
        var numberElements = frm.elements.le ngth-1;
        for(var i = 0; i < numberElements; i++) {
        queryString+=fr m.elements[i].name
        +"="+encodeURIC omponent(frm.el ements[i].value);
        if(i < numberElements-1) queryString+="& ";
        }
        >
        So for some reason, it was written to always skip the last element. I
        took out the -1 from "length-1" and it works as expected now. Thanks,
        you really helped.
        You should also only return controls that have a value for the name
        attribute, and do not expect select elements to return their value in
        all browsers (though likely those that don't aren't supported by your
        "AJAX" form anyway).

        You might also consider using an array to join the value/name pairs
        with '&', something like:

        function ... ()
        {
        var element, queryString = [];
        var numberElements = frm.elements.le ngth;

        for(var i=0; i<numberElement s; i++) {
        element = frm.elements[i];
        if (element.name && element.name != '') {
        queryString.pus h(element.name + "="
        + encodeURICompon ent(element.val ue));
        }
        }
        return queryString.joi n('&'); }
        }


        --
        Rob

        Comment

        Working...