473,671 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine FORM that contains a specific INPUT element?

I created this test routine to return the form containing a certain
input element:

function GetElementForm( element)
{
// Return the form that contains element.

var myElement = element;

while (myElement)
{
myElement = myElement.paren tNode;
if (myElement)
{
var sTagName = myElement.tagNa me;
if (sTagName)
{
if (sTagName.toLow erCase() == "form")
{
break;
}
}
}
}
return myElement;
}

This seems to work for "well formed" HTML, but fails for example, when
a form is defined within a table.

Is there a technique that works reliably?

Thanks,

Frank

Oct 11 '06 #1
2 1984
Frank wrote:
... return the form containing a certain input element:
[snip]
Is there a technique that works reliably?
formElement.for m

The property, form, is defined for all form controls (button, fieldset,
input, label, legend, object, option, select, textarea). If the controls
is a descendant of a form, the property will refer to that object - it
is null, otherwise.

Mike
Oct 11 '06 #2
Frank wrote:
<snip>
This seems to work for "well formed" HTML, but
fails for example, when a form is defined within
a table.
That is not true. A form can be defined within a table (specifically,
contained within a single TD or TH element) and the chain of parent nodes
of its form controls will include its form ancestor.

Generally, if you want to use a table to 'lay-out' form controls (a
reasonable thing to do in semantic HTML as forms can be tabular) you
would wrap the Form elements around the TABLE, and so (potentially) have
structurally valid HTML to start with.
Is there a technique that works reliably?
You could try following the general advice that if a document is to be
scripted it should always be a structurally valid document to start with.
Doing that completely avoids all the consequences of inconsistent and
unexpected DOM structures that result form browser error correction in
tag-soup documents. (That is; don't make things difficult for yourself
when a simple (potentially mechanised) quality check on the HTML can
eliminate many issues at a stroke).

Richard.
Oct 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12917
by: JT | last post by:
is there a way to determine if a form object actually exists? if i use the following syntax: varTextField = Request.Form("txtFormField") then varTextField = "" which gives the same result whether the input field "txtFormField" doesn't exist or it does exist but it was left empty why can't i use something like?
4
1385
by: Pawe³ | last post by:
We can access the Nth element in the first form by document.forms.elements imagine that theres function like <INPUT TYPE=TEXT" onclick="somefunction(this)"> and... we have function somefunction(obj) {
8
7152
by: L Major | last post by:
Hi Unfortunately, I am limited to using tables for part of my current project. I have a form that spans across a number of TR and TD in the shape of checkboxes. Doctype is XHTML 1.0 Transitional, Encoding is utf-8 Is there anything wrong? Should I try something else? What in that case?
18
2877
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
6
2736
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
5
1891
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 control2
3
2214
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image" name="MyImageButton" id="MyImageButton" src="somePic.jpg" /> I want for the code-behind to "know" when the user clicked on the image - but I don't want to also have to dynamically specify a delegate for an event procedure to handle this control which is really...
3
1410
by: Bill_W_Stephens | last post by:
I am modifying existing javascript code where the author appears to be passing an entire form to a javascript function called Require(). I want to add a new test: "is @BHFOR.value = blanks". Interestingly it works in Firefox but not IE so I suspect that the syntax is not correct. Is there a better way to test a specific element of the form in this case? Here is an extract of the code:
1
333
by: Frank | last post by:
I created this test routine to return the form containing a certain input element: function GetElementForm(element) { // Return the form that contains element. var myElement = element; while (myElement)
5
4015
by: mantrid | last post by:
Hello Im trying to find the correct syntax to use to determine whether which form element is visible on changing the value in a dropdown list I need something in the onChange of the dropdown list that will cause the appropriate element on another part of the page to be displayed pseudo code below var mydropdownlist =
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.