homepage Welcome to WebmasterWorld Guest from 54.205.197.66
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
validating to strict with textarea
sgml parser
Matthew1980




msg:4116181
 7:31 am on Apr 15, 2010 (gmt 0)

Hello everyone,

I had a problem last night that has suprised me, either that or I have not noticed it before:-

<div class="formcontainer">
<form method="post">
<textarea name="mytextarea">
Hi there!
</textarea><br/>
<input type="submit" name="submit" value="submit">
</form>
</div>

I thought as this would be perfectly fine going though the validator, but it turns out as it needs nesting :-

<div class="formcontainer">
<form method="post">
<p><textarea name="mytextarea">
Hi there!
</textarea>
</p>
<br/>
<p><input type="submit" name="submit" value="submit"></p>
</form>
</div>

Or is this just the difference between transitional & strict?

This may seem trivial, but I thought that having the entire form encased in 1 div would be ok, but adding the <p> tags around each element made it validate properly.

Maybee I have missed a day at html school somwhere along the line ;-p but it just caught me out for half hour last night.

Cheers,
MRb

 

kaled




msg:4116266
 10:48 am on Apr 15, 2010 (gmt 0)

There are some bonkers rules in strict, so I don't bother with it most of the time (except when I'm writing example code).

If you use a <div> within the <form> to contain all elements, it should be ok. This will avoid applying unwanted CSS rules for <p> to the <textarea>. I think I did this a while back for some bit of code somewhere but I'm not certain.

Kaled.

Matthew1980




msg:4116307
 12:30 pm on Apr 15, 2010 (gmt 0)

Hi there Kaled,

Yes, with respect to using a single div to "hold" a form,I thought as I would be Ok. There is no discernable difference having the <p> tags there or not, at least I cant see it. I suppose that this gives you the option of dressing up the elements aesthetics at a later date.

Cheers,
MRb

Fotiman




msg:4116349
 2:59 pm on Apr 15, 2010 (gmt 0)

As defined in the HTML 4.01 Spec. [w3.org], the form element can only contain block elements (like div and p) or script element.

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

Therefore, it's usually best to do something like this:

<form ...>
<div>
...
</div>
</form>

You can still have a "formcontainer" div around the form as well if you want, but it might make more sense to just make the inner div element the "formcontainer" (assuming you're styling that element in some way).

kaled




msg:4116397
 4:05 pm on Apr 15, 2010 (gmt 0)

I thought that's what I said, but not as clearly I guess!

Fotiman




msg:4116415
 4:22 pm on Apr 15, 2010 (gmt 0)

Yes, you did. I just wanted to clarify that this was not something new or specific to the strict DTD, and provide the details of "why". :)

Matthew1980




msg:4116553
 8:20 pm on Apr 15, 2010 (gmt 0)

Hi guys,

Thanks for the explanations, Kaled, you had explained perfectly, more than likely human error on my part! I since re-read the thread, and when I looked over the my code, I realised that I hadn't placed a div on the inside of the form, hence why I was surprised when placed a generic p tag in there and the strict validator came back as Ok. I had only placed one on the outside, the container in essence.

I have since placed an internal Div, instead of the p tags and everything is Ok.

I have only recently started to use strict, as I thought I was already coding to that standard within the context of transitional. I am too which is good news, just something as trivial as that caught me out ;-p

Again, thanks for the advice & links,

Cheers,
MRb

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved