473,721 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form and nested elements

Hi

I have a validation problem with a form and nested divs. I understand what
the problem is, but I don't see how to fix it. This is my normal page
structure, and it validates:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
</div>
<div>
<div>
<form name="form1" action="">
<p>Some form elements</p>
</form>
</div>
<div>
<form name="form2" action="">
<p>Some form elements</p>
</form>
</div>
</div>
</body>
</html>

Now the form has some additional elements in the first div:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<form name="form1" action="">
<p>Some form elements</p>
</div>
<div>
<div>
<p>Some more form elements</p>
</form>
</div>
<div>
<form name="form2" action="">
<p>Some form elements</p>
</form>
</div>
</div>
</body>
</html>

And due to improper nesting this does not validate. I tried the same thing
with a layout table, it does not validate either (neither in strict nor in
transitional mode). Note that form 2 is the reason why I can't span the form
over the whole body, which would make it validate without a problem.

Now in the early days I learnt that forms could begin and end inside or
outside any element, regardless of the layout or table structure. Is this
just outdated, or is there a possibility to declare a form as cross-element?

--
Markus
Jul 23 '05 #1
5 7402
On Wed, 10 Nov 2004 10:57:12 +0100, Markus Ernst <derernst@NO#SP #AMgmx.ch>
wrote:
<body>
<div>
<form name="form1" action="">
You've opened a div and a form.
<p>Some form elements</p>
</div>


Now you've closed the div. Therefore the form is also closed.
Jul 23 '05 #2

"Markus Ernst" <derernst@NO#SP #AMgmx.ch> wrote in message
news:41******** *************** @news.easynet.c h...
Hi

I have a validation problem with a form and nested divs. I understand what
the problem is, but I don't see how to fix it. This is my normal page
structure, and it validates:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
</div>
<div>
<div>
<form name="form1" action="">
<p>Some form elements</p>
</form>
</div>
<div>
<form name="form2" action="">
<p>Some form elements</p>
</form>
</div>
</div>
</body>
</html>

Now the form has some additional elements in the first div:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<form name="form1" action="">
<p>Some form elements</p>
</div>
<div>
<div>
<p>Some more form elements</p>
</form>
</div>
<div>
<form name="form2" action="">
<p>Some form elements</p>
</form>
</div>
</div>
</body>
</html>

And due to improper nesting this does not validate.
Right. *Everything* in HTML is nested. No partial overlapping allowed.
I tried the same thing
with a layout table, it does not validate either (neither in strict nor in
transitional mode). Note that form 2 is the reason why I can't span the form over the whole body, which would make it validate without a problem.

Now in the early days I learnt that forms could begin and end inside or
outside any element, regardless of the layout or table structure. Is this
just outdated, or is there a possibility to declare a form as

cross-element?

ISTR that if you wanted to lay out a form with a table in an old Netscape
version, you kind of had to put the FORM tags just inside the TABLE tags or
something like that, and IE didn't reject it when you did it that way.
Anyway, it's definitely wrong in current HTML.

Jul 23 '05 #3
Harlan Messinger wrote:
ISTR that if you wanted to lay out a form with a table in an old
Netscape version, you kind of had to put the FORM tags just inside
the TABLE tags or something like that, and IE didn't reject it when
you did it that way.
Actually both IE and Mozilla do not reject my page with the wrongly nested
form; they display it the way I want ("correctly" would not be the
appropriate term here).
Anyway, it's definitely wrong in current HTML.


I was afraid that would be the only possible answer, thank you.

--
Markus
Jul 23 '05 #4
Markus Ernst wrote:

<snip>Markup example with improperly nested form</snip>
And due to improper nesting this does not validate.
Note that form 2 is the reason why I can't span the form
over the whole body, which would make it validate without a problem.
There are never any occasions where you need improper nesting of
elements like you had, and doing so is exceptionally bad because, even
though current browsers can handle it as tag soup, it is handled very
differently in different browsers, and sometimes causes very different
results. So, you can never be sure what you'll get with improperly
nested elements in different browsers, unless you test them all, but it
should never be done anyway.

I suggest you think a little more about your document structure. They
were two seperate forms, so mark them up as that. If half of form one
was appearing in a seperate section, then that's most likely for
presentational reasons, I can't imagine any structural or semantic
reason to do so. You should also be able to remove a few of those
<div>s, and just apply styles directly to the form element. You should
generally avoid overusing divs, since they have no semantics, and often
serve to unnecessarily bloat your code, so use them sparingly.
Now in the early days I learnt that forms could begin and end inside or
outside any element, regardless of the layout or table structure. Is this
just outdated


It's not just outdated, it was never valid. It just means you were
taught by an ignorant teacher, or from a poorly written book.

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://SpreadFirefox.com/ Igniting the Web
Jul 23 '05 #5
Lachlan Hunt wrote:

It's not just outdated, it was never valid. It just means you were
taught by an ignorant teacher, or from a poorly written book.


Yes we also learnt how to write "You need a version 4 browser to view this
page"... Thanks for your comment.

--
Markus
Jul 23 '05 #6

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

Similar topics

12
3632
by: Frank Stephan | last post by:
Hi, im using Struts with nested tags for form validation. So I end up with form elements named like this risikenManuell.praemieNeu risikenManuell.praemieNeu .... I would like to do a calculation on the input values
5
8330
by: javaguy | last post by:
I have a data entry web application that is formatted heavily with tables. Having learned a bit of CSS, I'm hoping to rewrite this using <div> tags. But I have run into a formatting problem that keeps me from a solution. I'm hoping for some trick. Assume that "label_a" is a <label> tag and "INPUT_A" is an <input> tag. A sample of my current web page is: <table> <tr><td>label_a</td><td>INPUT_A</td>
2
1939
by: Cardinal | last post by:
In the application I'm developing, I need a link to behave as a form submit. I set up a little test example below and it worked fine: <table> <tr> <form action="action1.cfm" method="POST" enablecab="No" name="CareerActionPlanLink"> <td align="center"> <input type="Hidden" name="careerActionPlanID" value="7"> <a href="javascript:document.CareerActionPlanLink.submit();">Edit</a>
5
2824
by: horndude77 | last post by:
Ok, this might be for a web designing group, but here's my problem. I'm trying to make a web page with tabs which you can navigate between without the page reloading. I have one set of tabs working great, but when I add nested tabs there is a problem with the 'visibility' not being inherited and some parts stay visible in the sub-tabs. Sorry if this is unclear. Here's how I have it layed out: I have a <span> for each content section of...
2
1861
by: George | last post by:
How can I do the following in python: given two strings: form=""" <html> <head> <title> My Sample Web Page </title> </head> <body bgcolor="white"> <p> What are the weekdays? <ol>
4
13329
by: Alex Maghen | last post by:
I have a master page which contains a general page framework and also contains a <form runat=server> around most of the content of the page. Inside that <form> tag is a ContentPlaceholder. I then create an ASPX which is tied to that MasterPage and in it a put a bunch of form fields and an <asp:Button />. When I try to run the page, I get... "Control 'ctl00_BodyCPH_ctl00' of type 'Button' must be placed inside a form tag with...
1
16756
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
1
11808
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an XmlNodeList. I am trying to deserialize the nodes using a foreach as follows: foreach(XmlNode lineItem in LineItemsNodeList) An abbreviated example of the nested lineItem node looks like this:
1
2433
by: Henrik Bechmann | last post by:
All, I'm trying to spoof Google's vertical tabs in a vertical menu structured with nested UL/LI elements. To do this, I need to find out where the anchor in the LI is, and then create an absolute positioned div to bridge the space between the menu and the content page. This works with one level of LI's. However, with more than one, the
0
8730
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
9215
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...
1
9131
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8007
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5981
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
4484
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...
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.