Valid inputs

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Valid inputs

Post by shiznatix »

I am trying to make everything 100% valid XHTML. The only real problem I am coming across is this:

Code: Select all

<form action="asdsdf.php" method="post">
    <input type="submit" value="Submit" />
</form>
That is NOT valid XHTML strict. It says I cant put a input there. If I do this:

Code: Select all

<form action="asdsdf.php" method="post">
    <div style="display: inline;">
         <input type="submit" value="Submit" />
    </div>
</form>
Then it is valid. Now do I really have to go around and put a div tag everywhere I want to have an input type to make it valid? Seams silly to me and does not make sence to me why the first is not valid.

If someone could shed some light that would be fantastic.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

You don't need divs. I'd use a p tag to put around the input. Note that if you want your inputs lined up horizontally, you can just put them after each other inside the p (or div) tag. No need for display:inline tricks.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

And/or use a label.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

aye but I have to put them in something? I dont see why a input type hidden should have to be inside a p or a div or anything other than a form. Seams silly. Sigh, ill do it though.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

In XHTML a <form> is not a layout component, although it does change the layout somewhat in most browsers. Grr.

You should almost always wrap inputs in labels like so:

Code: Select all

<label>Name: <input name="name" type="text"/></label>
As for hidden fields, you could either wrap them in hidden divs or just be a rebel and fail validation.

It feels good to validate, but it feels even better to know why you don't need to!

Cheers,
Kieran
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

Kieran Huggins wrote:In XHTML a <form> is not a layout component, although it does change the layout somewhat in most browsers. Grr.
Right. Setting margin and padding to zero helps a lot though.
You should almost always wrap inputs in labels like so:

Code: Select all

<label>Name: <input name="name" type="text"/></label>
Or like this:

Code: Select all

<p><label for="name">Name:</label> <input id="name" name="name" type="text"/></p>
It feels good to validate, but it feels even better to know why you don't need to!
Sure. Validation doesn't mean everything. It is perfectly possible to create a valid xhtml 1.0 mess.
Post Reply