Submit or not submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wim Roffal

    Submit or not submit

    If I declare in a form a field with an id but without a name it will not be
    submitted.
    However, once I assign a name to it it seems that I am not able to undo
    this.

    If I say in javascript...

    MyForm.MyField. name='fíeld1';
    MyForm.MyField. name='';

    ....the result is a fieldname of length zero that is still submitted.

    Similarly the delete operator does not work. If I write...

    delete MyForm.MyField. name;

    .... I get an error message.

    Are there ways to accomplish what I want?

    Thanks,
    Wim


  • Michael Winter

    #2
    Re: Submit or not submit

    Wim Roffal wrote on 22 Nov 2003:
    [color=blue]
    > If I declare in a form a field with an id but without a name it
    > will not be submitted.[/color]

    <snip>

    If all you want to do is stop a control from being submitted, disable
    it, like so:

    document.forms['form_name'].elements['control_name'].disabled = true;

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Submit or not submit

      "Wim Roffal" <wimroffelpleas e@nospamm-planet.nl> writes:
      [color=blue]
      > If I declare in a form a field with an id but without a name it will not be
      > submitted.[/color]

      Correct. According to the HTML specification, for a form control to be
      successful (i.e., it will be submitted), it must have a control name.
      [color=blue]
      > However, once I assign a name to it it seems that I am not able to undo
      > this.
      >
      > If I say in javascript...
      >
      > MyForm.MyField. name='fíeld1';
      > MyForm.MyField. name='';
      >
      > ...the result is a fieldname of length zero that is still submitted.[/color]

      It *is* a name property with a value that happens to be the empty
      string. It's very much there.
      [color=blue]
      > Similarly the delete operator does not work. If I write...
      >
      > delete MyForm.MyField. name;
      >
      > ... I get an error message.[/color]

      That surprices me. That was what I would have suggested.
      What error do you get?
      [color=blue]
      > Are there ways to accomplish what I want?[/color]

      You can also try
      document.forms. MyForm.elements .MyField.name = undefined;
      It is not exactly the same as deleting the property,
      but it is close.

      (And that was a hint not to use the form ID as a global variable. It
      won't work in, e.g., Mozilla/Netscape 6).

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Wim Roffal

        #4
        Re: Submit or not submit

        Michael and Lasse, thanks for your replies:

        "Michael Winter" <M.Winter@bluey onder.co.uk.inv alid> schreef in bericht
        news:Xns943B830 282A77MWinterBl ueyonder@193.38 .113.46...[color=blue]
        > Wim Roffal wrote on 22 Nov 2003:
        >
        > document.forms['form_name'].elements['control_name'].disabled = true;[/color]

        In this case I don't want the field disabled. The form is submitted in an
        iframe, so I want to keep my page whole.

        "Lasse Reichstein Nielsen" <lrn@hotpop.com > schreef in bericht
        news:3ccg365n.f sf@hotpop.com.. .[color=blue]
        > "Wim Roffal" <wimroffelpleas e@nospamm-planet.nl> writes:[color=green]
        > > Similarly the delete operator does not work. If I write...
        > >
        > > delete MyForm.MyField. name;
        > >
        > > ... I get an error message.[/color]
        >
        > That surprices me. That was what I would have suggested.
        > What error do you get?[/color]

        (translated form dutch) This action is not supported by this object.[color=blue]
        >[color=green]
        > > Are there ways to accomplish what I want?[/color]
        >
        > You can also try
        > document.forms. MyForm.elements .MyField.name = undefined;
        > It is not exactly the same as deleting the property,
        > but it is close.[/color]

        I tried it. But if I do this I it will submit the field with fieldname
        "undefined" . (yes, I did not use quotes).
        [color=blue]
        > (And that was a hint not to use the form ID as a global variable. It
        > won't work in, e.g., Mozilla/Netscape 6).[/color]

        Thanks for the tip. I am testing this in IE 5.5 now.

        Wim


        Comment

        • Janwillem Borleffs

          #5
          Re: Submit or not submit


          "Wim Roffal" <wimroffelpleas e@nospamm-planet.nl> schreef in bericht
          news:bpnrfh$2d5 $1@reader10.wxs .nl...[color=blue][color=green]
          > >
          > > You can also try
          > > document.forms. MyForm.elements .MyField.name = undefined;
          > > It is not exactly the same as deleting the property,
          > > but it is close.[/color]
          >
          > I tried it. But if I do this I it will submit the field with fieldname
          > "undefined" . (yes, I did not use quotes).
          >[/color]

          What you can do, is remove the element by using the removeChild method:

          function remove(f, e) {
          var index = null;
          for (var i = 0; i < f.childNodes.le ngth; i++) {
          if (f.childNodes.i tem(i).name == e) {
          index = i;
          break;
          }
          }
          if (index === null) return;
          return f.removeChild(f .childNodes.ite m(index));
          }
          ....

          <form method="get" action="">
          <input type="hidden" name="element_a " value="1" />
          <input type="hidden" name="element_b " value="1" />
          <input type="button" value="remove element_a"
          onclick="remove (form,'element_ a')" />
          <input type="button" value="remove element_b"
          onclick="remove (form,'element_ b')" />
          </form>


          JW



          Comment

          • Janwillem Borleffs

            #6
            Re: Submit or not submit


            "Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht
            news:3fbf7a4c$0 $118$1b62eedf@n ews.wanadoo.nl. ..[color=blue]
            >
            > function remove(f, e) {
            > var index = null;
            > for (var i = 0; i < f.childNodes.le ngth; i++) {
            > if (f.childNodes.i tem(i).name == e) {
            > index = i;
            > break;
            > }
            > }
            > if (index === null) return;
            > return f.removeChild(f .childNodes.ite m(index));
            > }
            > ...[/color]

            This looks nicer and does the same:

            function remove(f, e) {
            for (var i = 0; i < f.childNodes.le ngth; i++) {
            if (f.childNodes.i tem(i).name == e) {
            return f.removeChild(f .childNodes.ite m(i));
            }
            }
            }


            JW



            Comment

            • VK

              #7
              Re: Submit or not submit

              I would say - Submit! :-)
              And filter the submission on the server side (like all filelds with ""
              value do not count).

              On the client side you may use DOM:

              with (document.myFor m) {
              removeChild(ele ments('myElemen t'));
              }

              Still not exactly what you want: it doesn't exclude an element from the
              submission, it removes the element itself.


              Comment

              Working...