SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing class of a object during an error for usability

    In a form I'm building, if a inputted value is invalid, I'm giving them a JavaScript alert (as my first defense) to tell the user there's a problem, and having them fix the problem, before the form can be submitted.

    Each question is in it's own paragraph, and each paragraph has it's own id.

    For usability issues, I thought it would be nice to change the class of the paragraph, to one with a highlighted background. That, in addition to the specific error in the alert, would make finding and fixing the error so much easier for the end user.

    So I'm trying to change the class of my paragraphs, if an error occurs.

    This is what I have so far, but it giving me a Null or Not an Object error.

    document.getElementById(q1).className=error;

    Any advice?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you mean this:
    Code:
    document.getElementById('q1').className='error';
    If that isn't what you want, then you'll need to show us more code.

    You could also use focus() to give focus to a text box with incorrect input.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •