tags:

views:

136

answers:

3

I am using a few page validation tools one problem i have is they tell me textarea must have rows and cols attribute. If i am setting this in CSS or using display:none (and using it to hold raw text data) can i do something to skip? it seems like the only answer is rows="0" cols="0" each time i use it. But i have a feeling that is not a good solution.

A: 

I think, it's standard solution. It would be better to give larger values though, so that browsers with disabled CSS can show them correctly. For invisible data holders you can use <div> instead of <textarea>.

binaryLV
+4  A: 

Stop using a textarea. If you want something to hold raw data, then use a <script> element (if you plan to access it with JS) or an input of type hidden (if you plan to submit it as form data).

Don't use semantics that say "Let the user enter data" if you don't plan to let the user enter data.

David Dorward
hmm. that sounds like a better solution (i dont know why ppl told me textarea in the past). How do i find the JS data? i have been using var data = $(this).parent('.parent').find('.valuestr').eq(0).val(); which is fairly easy. I cant imagine a just as easy way if i put it in JS
acidzombie24
`<script type="text/javascript">var global_data = 'your data'; function func() { var data = global_data; }</script>`
binaryLV
binaryLV: Thats not the same. Mine is relative to the div i clicked. global_data is ONE big fat data.
acidzombie24
Then `usefulname = usefulname || {}; usefulname.id_of_element = { ... };` and later `usefulname[this.id]`
David Dorward
Sounds good. I'll accept as a solution. But why do i not want to use textarea again? considering my site will look like hell without css (as per spec) this solution doesnt seem as simple as storing it in a textarea. +1
acidzombie24
Having the data in JS is much simpler then walking up the DOM and back down the DOM to find the control. If the spec says it should "look like hell without CSS" then it is a bad spec.
David Dorward
A: 

David's answer is ultimately the right one. A quick note about required attributes, though: Many attributes are required to be present, but are not required to have a value - so <textarea rows="" cols=""></textarea> is perfectly valid.

Semantically, think of this as explicitly not specifying the rows or cols, which is different to <textarea></textarea> which is just ignoring the attributes completely.

Beejamin
David Dorward
Hmmm. It *is* valid XHTML 1.0, but the DTD says: `<!ENTITY % Number "CDATA"> <!-- one or more digits -->`. So it is still wrong, its just (I assume) that XML DTDs aren't expressive enough to tell the validator about that requirement. So it is still a conformance error, just not a validity error. I'll chalk this up as yet another reason to not use XHTML.
David Dorward
Interesting, David - I admit that when I first found out about the validity of no-value attributes, I was a bit surprised. I didn't realise it was an XHTML only thing, though - thanks for the heads-up!
Beejamin