473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 23 '05 #1
8 1320
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
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

"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

"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan Capps | last post by:
I have a text box control on a form, the value of which is calculated (concatenated) from entries on a subform. Accordingly, I've set the control's locked property to true and the tab stop...
12
by: MLH | last post by:
I have created two forms: frmBrowseNegsMainform and frmBrowseNegsSubform. I put a subform control on the first of these. The SourceObject property for the subform control is, of course,...
3
by: Not Me | last post by:
Hi, Just trying to get my head around tab controls, is there anywhere which would describe the structure of how they work? I seem to be ok so far, being able to check which page I'm on etc......
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
7
by: Tom wilson | last post by:
I'm trying to create dynamic controls in ASP.Net. It's driving me nuts. I keep getting the error: Control '16' of type 'RadioButton' must be placed inside a form tag with runat=server. Dim...
11
by: PAul Maskens | last post by:
The form designer adds unnecessary code to the section when using a subclassed control. I've reproduced this in VS.NET 2002 and VS.NET 2003 so it's pretty fundamental. Outline steps: Create a...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
7
by: ApexData | last post by:
I am using the following code in my TabControl to manage subform loads. The code assigns the subForms SourceObject. - Do I also need code to DeAssign the SourceObject when leaving the Tab, I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.