By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,723 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

How do I add a control to a form.

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Mike R wrote:
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


Quick guess:

var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
ocontainer.frm1.appendChild(hfield);
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;

Jul 23 '05 #2

P: n/a
RobB wrote:

[snip]
var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
It's preferable to use the shortcut properties in HTML documents. That is,

hfield.type = 'hidden';

and so on.
ocontainer.frm1.appendChild(hfield);
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.
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


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.
Jul 23 '05 #3

P: n/a

"RobB" <fe******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Mike R wrote:
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


Quick guess:

var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
ocontainer.frm1.appendChild(hfield);
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


Thanks Rob and Mike, I will give it a go
Jul 23 '05 #4

P: n/a

"RobB" <fe******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Mike R wrote:
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


Quick guess:

var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
ocontainer.frm1.appendChild(hfield);
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


Hi

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

my code :

var oGridContainerWindow =
document.getElementById("crmGrid0").contentWindow;

var hfield = document.createElement('input');

hfield.type = 'hidden';

hfield.id = 'rowHeight';
oGridContainerWindow.frmGrid.appendChild(hfield);


Jul 23 '05 #5

P: n/a
Hi Mike.

Michael Winter wrote:
RobB wrote:

[snip]
var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
It's preferable to use the shortcut properties in HTML documents.

That is,
hfield.type = 'hidden';

and so on.
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.
ocontainer.frm1.appendChild(hfield);


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.


Just conforming to the OPs description.
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


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.


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

Jul 23 '05 #6

P: n/a

"Mike R" <ne**@mikeread.freeserve.co.uk> wrote in message
news:d0*******************@news.demon.co.uk...

"RobB" <fe******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Mike R wrote:
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


Quick guess:

var hfield = document.createElement('input');
hfield.setAttribute('type', 'hidden');
hfield.setAttribute('name', 'somename');
hfield.setAttribute('value', 'somevalue');
ocontainer.frm1.appendChild(hfield);
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


Hi

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

my code :

var oGridContainerWindow =
document.getElementById("crmGrid0").contentWindow;

var hfield = document.createElement('input');

hfield.type = 'hidden';

hfield.id = 'rowHeight';
oGridContainerWindow.frmGrid.appendChild(hfield);


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

and that worked

Jul 23 '05 #7

P: n/a
Mike R wrote:

(snip)
Hi

I get invalid argument with this ocontainer.frm1.appendChild(hfield);
my code :

var oGridContainerWindow =
document.getElementById("crmGrid0").contentWindow;

var hfield = document.createElement('input');

hfield.type = 'hidden';

hfield.id = 'rowHeight';
oGridContainerWindow.frmGrid.appendChild(hfield);


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

and that worked


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

Glad you got it sorted out.

Jul 23 '05 #8

P: n/a
RobB wrote:

[setAttribute vs. convenience properties]
I think it's preferable to use DOM Level 1+ methods whenever feasible,
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]
ocontainer.frm1.somename = hfield;
ocontainer.frm1.elements.somename = hfield;


[snip]
not implemented in current versions of MSIE.


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.
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.