Grow your CSS skills. Land your dream job.

Opinion: using JavaScript to style forms

  • # April 30, 2009 at 12:20 pm

    Lets say you’re developing a rather large web application with lots of forms. What do you think about using JavaScript to set the proper classes for styling these forms instead of marking them up with the styles embedded? Let’s also assume, for the sake of argument, that JavaScript is already required for the web app to function properly.

    The idea is that a formStyling.js could be included that would scan all the necessary form elements when the document is ready and apply the styles appropriately. This way, you don’t need any additional markup on the form elements (like applying a "text" class to text inputs, etc., etc.). Also, you’d be able to change the actual name of the class or how and when the classes are applied from a central location; otherwise, when the name of a class or when it gets applied changes you’d have to change every instance throughout your application.

    So, what do you all think about this approach? I’m sure there are drawbacks. Just a little discussion.

    # April 30, 2009 at 5:08 pm

    The key sentence was that JavaScript is required for the app to function properly.

    Generally requiring JavaScript to make forms work is frowned upon, since users without it (by choice or not), shouldn’t be discriminated against by not being able to use a site. But… if this is A) merely aesthetic and B) would be broken anyway, I’d say go for it.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".