How do I add a control to a form.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike R

    How do I add a control to a form.

    Hi,

    I have a form frm1 . The form is generated by a "control" that is placed on
    the page - I have no access to the source to modify the controls. I can
    access other hidden controls within it by referencing:

    ocontainer.frm1 .txt1.value;

    I would like to insert my own hidden control that can be posted back to to
    my page so I can do something with it. How can I do this from clientside at
    runtime?

    Thanks

    Mike


  • RobB

    #2
    Re: How do I add a control to a form.

    Mike R wrote:[color=blue]
    > Hi,
    >
    > I have a form frm1 . The form is generated by a "control" that is[/color]
    placed on[color=blue]
    > the page - I have no access to the source to modify the controls. I[/color]
    can[color=blue]
    > access other hidden controls within it by referencing:
    >
    > ocontainer.frm1 .txt1.value;
    >
    > I would like to insert my own hidden control that can be posted back[/color]
    to to[color=blue]
    > my page so I can do something with it. How can I do this from[/color]
    clientside at[color=blue]
    > runtime?
    >
    > Thanks
    >
    > Mike[/color]

    Quick guess:

    var hfield = document.create Element('input' );
    hfield.setAttri bute('type', 'hidden');
    hfield.setAttri bute('name', 'somename');
    hfield.setAttri bute('value', 'somevalue');
    ocontainer.frm1 .appendChild(hf ield);
    ocontainer.frm1 .somename = hfield;
    ocontainer.frm1 .elements.somen ame = hfield;

    Comment

    • Michael Winter

      #3
      Re: How do I add a control to a form.

      RobB wrote:

      [snip]
      [color=blue]
      > var hfield = document.create Element('input' );
      > hfield.setAttri bute('type', 'hidden');
      > hfield.setAttri bute('name', 'somename');
      > hfield.setAttri bute('value', 'somevalue');[/color]

      It's preferable to use the shortcut properties in HTML documents. That is,

      hfield.type = 'hidden';

      and so on.
      [color=blue]
      > ocontainer.frm1 .appendChild(hf ield);[/color]

      The element that should be used a container may vary by DOCTYPE. A
      Transitional document can use a FORM element directly. With Strict,
      the container should be a block-level element within the form.
      [color=blue]
      > ocontainer.frm1 .somename = hfield;
      > ocontainer.frm1 .elements.somen ame = hfield;[/color]

      That's unnecessary. Inserting a form control into a form automatically
      adds it to the elements collection and sets the form property on the
      control. This even occurs if the new element is not a child of the
      form, but a descendant.

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • Mike R

        #4
        Re: How do I add a control to a form.


        "RobB" <ferndoc9@hotma il.com> wrote in message
        news:1110303838 .443391.182920@ z14g2000cwz.goo glegroups.com.. .[color=blue]
        > Mike R wrote:[color=green]
        >> Hi,
        >>
        >> I have a form frm1 . The form is generated by a "control" that is[/color]
        > placed on[color=green]
        >> the page - I have no access to the source to modify the controls. I[/color]
        > can[color=green]
        >> access other hidden controls within it by referencing:
        >>
        >> ocontainer.frm1 .txt1.value;
        >>
        >> I would like to insert my own hidden control that can be posted back[/color]
        > to to[color=green]
        >> my page so I can do something with it. How can I do this from[/color]
        > clientside at[color=green]
        >> runtime?
        >>
        >> Thanks
        >>
        >> Mike[/color]
        >
        > Quick guess:
        >
        > var hfield = document.create Element('input' );
        > hfield.setAttri bute('type', 'hidden');
        > hfield.setAttri bute('name', 'somename');
        > hfield.setAttri bute('value', 'somevalue');
        > ocontainer.frm1 .appendChild(hf ield);
        > ocontainer.frm1 .somename = hfield;
        > ocontainer.frm1 .elements.somen ame = hfield;
        >[/color]

        Thanks Rob and Mike, I will give it a go


        Comment

        • Mike R

          #5
          Re: How do I add a control to a form.


          "RobB" <ferndoc9@hotma il.com> wrote in message
          news:1110303838 .443391.182920@ z14g2000cwz.goo glegroups.com.. .[color=blue]
          > Mike R wrote:[color=green]
          >> Hi,
          >>
          >> I have a form frm1 . The form is generated by a "control" that is[/color]
          > placed on[color=green]
          >> the page - I have no access to the source to modify the controls. I[/color]
          > can[color=green]
          >> access other hidden controls within it by referencing:
          >>
          >> ocontainer.frm1 .txt1.value;
          >>
          >> I would like to insert my own hidden control that can be posted back[/color]
          > to to[color=green]
          >> my page so I can do something with it. How can I do this from[/color]
          > clientside at[color=green]
          >> runtime?
          >>
          >> Thanks
          >>
          >> Mike[/color]
          >
          > Quick guess:
          >
          > var hfield = document.create Element('input' );
          > hfield.setAttri bute('type', 'hidden');
          > hfield.setAttri bute('name', 'somename');
          > hfield.setAttri bute('value', 'somevalue');
          > ocontainer.frm1 .appendChild(hf ield);
          > ocontainer.frm1 .somename = hfield;
          > ocontainer.frm1 .elements.somen ame = hfield;
          >[/color]

          Hi

          I get invalid argument with this ocontainer.frm1 .appendChild(hf ield);

          my code :

          var oGridContainerW indow =
          document.getEle mentById("crmGr id0").contentWi ndow;

          var hfield = document.create Element('input' );

          hfield.type = 'hidden';

          hfield.id = 'rowHeight';


          oGridContainerW indow.frmGrid.a ppendChild(hfie ld);




          Comment

          • RobB

            #6
            Re: How do I add a control to a form.

            Hi Mike.

            Michael Winter wrote:[color=blue]
            > RobB wrote:
            >
            > [snip]
            >[color=green]
            > > var hfield = document.create Element('input' );
            > > hfield.setAttri bute('type', 'hidden');
            > > hfield.setAttri bute('name', 'somename');
            > > hfield.setAttri bute('value', 'somevalue');[/color]
            >
            > It's preferable to use the shortcut properties in HTML documents.[/color]
            That is,[color=blue]
            >
            > hfield.type = 'hidden';
            >
            > and so on.[/color]

            Hmm..I demur. I think it's preferable to use DOM Level 1+ methods
            whenever feasible, avoiding them where cross-browser implementation is
            uneven (and there's a better way). setAttribute() for these cases is
            reliable in my experience.
            [color=blue][color=green]
            > > ocontainer.frm1 .appendChild(hf ield);[/color]
            >
            > The element that should be used a container may vary by DOCTYPE. A
            > Transitional document can use a FORM element directly. With Strict,
            > the container should be a block-level element within the form.[/color]

            Just conforming to the OPs description.
            [color=blue][color=green]
            > > ocontainer.frm1 .somename = hfield;
            > > ocontainer.frm1 .elements.somen ame = hfield;[/color]
            >
            > That's unnecessary. Inserting a form control into a form[/color]
            automatically[color=blue]
            > adds it to the elements collection and sets the form property on the
            > control. This even occurs if the new element is not a child of the
            > form, but a descendant.[/color]

            Not intended to add it to elements[], just to create the usual
            references at Form.element_na me and Form.elements.e lement_name, not
            implemented in current versions of MSIE.

            Comment

            • Mike R

              #7
              Re: How do I add a control to a form.


              "Mike R" <news@mikeread. freeserve.co.uk > wrote in message
              news:d0kqeq$2m3 $1$8300dec7@new s.demon.co.uk.. .[color=blue]
              >
              > "RobB" <ferndoc9@hotma il.com> wrote in message
              > news:1110303838 .443391.182920@ z14g2000cwz.goo glegroups.com.. .[color=green]
              >> Mike R wrote:[color=darkred]
              >>> Hi,
              >>>
              >>> I have a form frm1 . The form is generated by a "control" that is[/color]
              >> placed on[color=darkred]
              >>> the page - I have no access to the source to modify the controls. I[/color]
              >> can[color=darkred]
              >>> access other hidden controls within it by referencing:
              >>>
              >>> ocontainer.frm1 .txt1.value;
              >>>
              >>> I would like to insert my own hidden control that can be posted back[/color]
              >> to to[color=darkred]
              >>> my page so I can do something with it. How can I do this from[/color]
              >> clientside at[color=darkred]
              >>> runtime?
              >>>
              >>> Thanks
              >>>
              >>> Mike[/color]
              >>
              >> Quick guess:
              >>
              >> var hfield = document.create Element('input' );
              >> hfield.setAttri bute('type', 'hidden');
              >> hfield.setAttri bute('name', 'somename');
              >> hfield.setAttri bute('value', 'somevalue');
              >> ocontainer.frm1 .appendChild(hf ield);
              >> ocontainer.frm1 .somename = hfield;
              >> ocontainer.frm1 .elements.somen ame = hfield;
              >>[/color]
              >
              > Hi
              >
              > I get invalid argument with this ocontainer.frm1 .appendChild(hf ield);
              >
              > my code :
              >
              > var oGridContainerW indow =
              > document.getEle mentById("crmGr id0").contentWi ndow;
              >
              > var hfield = document.create Element('input' );
              >
              > hfield.type = 'hidden';
              >
              > hfield.id = 'rowHeight';
              >
              >
              > oGridContainerW indow.frmGrid.a ppendChild(hfie ld);
              >
              >[/color]

              Ignore this, I used var hfield =
              oGridContainerW indow.document. createElement(' input');

              and that worked[color=blue]
              >
              >[/color]


              Comment

              • RobB

                #8
                Re: How do I add a control to a form.

                Mike R wrote:

                (snip)
                [color=blue][color=green]
                > > Hi
                > >
                > > I get invalid argument with this[/color][/color]
                ocontainer.frm1 .appendChild(hf ield);[color=blue][color=green]
                > >
                > > my code :
                > >
                > > var oGridContainerW indow =
                > > document.getEle mentById("crmGr id0").contentWi ndow;
                > >
                > > var hfield = document.create Element('input' );
                > >
                > > hfield.type = 'hidden';
                > >
                > > hfield.id = 'rowHeight';
                > >
                > >
                > > oGridContainerW indow.frmGrid.a ppendChild(hfie ld);
                > >
                > >[/color]
                >
                > Ignore this, I used var hfield =
                > oGridContainerW indow.document. createElement(' input');
                >
                > and that worked[color=green]
                > >
                > >[/color][/color]

                Very sneaky, leaving out the part about the iframe. #;=)

                Glad you got it sorted out.

                Comment

                • Michael Winter

                  #9
                  Re: How do I add a control to a form.

                  RobB wrote:

                  [setAttribute vs. convenience properties]
                  [color=blue]
                  > I think it's preferable to use DOM Level 1+ methods whenever feasible,[/color]

                  On what grounds? The convenience properties were provided explicitly
                  for HTML documents to provide a simple and efficient method of
                  altering the attributes of HTML elements.

                  If /true/ XHTML were an issue, and it shouldn't be for a long time
                  yet, there would be little option than to use methods. However, given
                  the opportunity, why not take the shorter route?

                  [snip]
                  [color=blue][color=green][color=darkred]
                  >>> ocontainer.frm1 .somename = hfield;
                  >>> ocontainer.frm1 .elements.somen ame = hfield;[/color][/color][/color]

                  [snip]
                  [color=blue]
                  > not implemented in current versions of MSIE.[/color]

                  You know, I never noticed that. The inserted elements do exist within
                  the elements collection, but not as named properties. How odd. I had
                  noticed problems with other collections - for example, the links
                  collection which doesn't expose any named properties - but I didn't
                  think it extended to forms.

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  Working...