Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

appendInputTypeClasses() - IE attribute selectors for form inputs

(Stolen from Jeremy Keith and Dustin Diaz:

Unobtrusive script takes a form inputs type attribute and copies it to that input's class. So, you go from...

<input type="text" />

<input type="text" class="text" />

Basically allows attribute selectors for form until IE catches up.

        AUTH: Austin Govella ([email protected])
        DATE: 2006-07-01
        DESC: Includes form specific javascripts.
        NOTE: Stolen from Jeremy Keith and Dustin Diaz:

function appendInputTypeClasses()
{       /* adds input type as the inputs class */
        if ( !document.getElementsByTagName ) return;

        var inputs = document.getElementsByTagName('input');
        var inputLen = inputs.length;
        for ( i=0; i < inputLen; i++ )
                if ( inputs[i].getAttribute('type') )
                        inputs[i].className += ' '+inputs[i].getAttribute('type');

Test whether an SGML attribute value requires quoting

SGML attribute values don't always need to be quoted; here's a quick bit of Python which returns whether an attribute value needs to be quoted or not:

import re
if re.compile('^[a-zA-Z0-9_\-\.:]+$').search(value):
   ...does not need quoting..
   ...does need quoting...
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed