tags:

views:

513

answers:

3

Hi,

I know that I should put all the html elements in body tag, but I need to put two hidden input above html dtd. I guess it does not make my html file as standard, but is it that bad? I have following code.

<input type='hidden' id='current_controller'>
<input type='hidden' id='current_module'>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

what are risks? so far, I do not have any problems.

+3  A: 

The risks are, IIRC, that IE6 has trouble with doctype if it's not the first line. It's also not standard practice, and could cause quirks in other browsers (but I believe most should be forgiving).

It also seems you're using XHTML... therefore those input elements should be self closing as they don't have end tags.

<input type='hidden' id='current_controller' />
<input type='hidden' id='current_module' />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Is there any reason why they must be there? Why can't they be placed inside the body element somewhere? I can't see any real use if they don't have a value attribute, unless you're checking for their existence, or adding the value attribute via JavaScript (which means you could also add these elements themselves via JavaScript).

alex
+1  A: 

The risks are that since your document is not valid, it will potentially not be rendered correctly in some browsers or in different versions of the same browser (and even future versions of browsers for which this might work currently.)

I'm not sure what the case might be such that you'd need to do this. What problem are you trying to solve with this approach, perhaps there is another question in there trying to get out? :)

fd
+2  A: 

If you're actually serving this as XHTML and thus having it run through an XML parser, it won't render as the markup is not valid.

Chuck
+1 good answer, didn't think of that!
alex