Results 1 to 8 of 8

Thread: W3C validation error with "required" option in form input

  1. #1
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default W3C validation error with "required" option in form input

    It's a small problem but I have a program with the following piece of code and I get a W3C validation error.

    <label>First Name:</label>
    <input type="text" id="fname" name="fname" value="" size="20" maxlength="20" required="required" /
    <label>Last Name:</label>
    <input type="text" id="lname" name="lname" value="" size="30" maxlength="30" required="required" />

    I only get an error on line 2, and not on line 4

    Does it have something to do with:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    Last edited by mcolton; 06-25-2014 at 03:33 PM.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Its more helpful if you post the actual error but I can see here that you've forgot the angle bracket at the end of the input element;
    Code:
    <input type="text" id="fname" name="fname" value="" size="20" maxlength="20" required="required" />
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Sorry. The angle bracket is actually there. I cut it off when putting it here

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    The reported error message will tell you what's invalid. What does it say?

    If it says there is no attribute "required" then it means that your chosen doctype does not support the 'required' attribute.

    Bear in mind that validation errors can trickle down from problems higher up in the page, and false negatives may be reported, so this might not be the most effective way to troubleshoot. You'd probably be better off posting the validation report with your whole page loaded in (or a link to your full page so that we can paste it in to the validator)
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Error Line 52, Column 97: there is no attribute "required"
    …me="fname" value="" size="20" maxlength="20" required="required" />

    I also tried it with just: required and not required="required". Same error.

    Code is at www.lotatennis.com under "Headlines" at "Existing Member Information Page"
    Thanks for the help

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    See:

    http://www.w3schools.com/tags/att_input_required.asp

    where it states that it (required) is an HTML 5 attribute. That means it will not validate to other DOCTYPES.

    Notice also its proper usages on that page:

    HTML Code:
    <form action="demo_form.asp">
    Username: <input type="text" name="usrname" required>
    <input type="submit">
    </form>
    Not required="required"

    Here is the the HTML 5 DOCTYPE:

    HTML Code:
    <!DOCTYPE html>
    Use it instead of:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Thanks. I've updated a lot of code recently and they all have the long doctype.
    Should I change them all to <!DOCTYPE html>

    All the others have no errors in W3C

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The HTML 5 DOCTYPE has requirements that your old code might or might not satisfy. If you're object is validation, perhaps you should not update validation error free pages. It all depends upon how much work is needed/you are willing to do in order to validate to the HTML 5 DOCTYPE. Most browsers will error correct and/or ignore minor validation errors. But they will not support something they are not designed to support. That means that older browsers may not support all of the latest usages, regardless of DOCTYPE and that most modern browser will support HTML 5 usages (if they do at all) in older DOCTYPES).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    mcolton (06-25-2014)

Similar Threads

  1. "Required field(s) validation" Quirk/Bug in Chrome
    By JohnCC in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 05-04-2012, 03:12 PM
  2. Replies: 1
    Last Post: 02-27-2009, 07:17 AM
  3. validation for <INPUT TYPE="FILE">
    By PradheepAyyanar in forum JavaScript
    Replies: 12
    Last Post: 07-16-2008, 04:12 PM
  4. Javascript "Object Required" error in IE 6
    By svoltmer in forum JavaScript
    Replies: 1
    Last Post: 05-06-2008, 09:40 PM
  5. Replies: 1
    Last Post: 06-25-2007, 12:31 PM

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
  •