View Full Version : Resolved W3C validation error with "required" option in form input
mcolton
06-25-2014, 11:08 AM
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">
Beverleyh
06-25-2014, 01:58 PM
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;
<input type="text" id="fname" name="fname" value="" size="20" maxlength="20" required="required" />
mcolton
06-25-2014, 02:51 PM
Sorry. The angle bracket is actually there. I cut it off when putting it here
Beverleyh
06-25-2014, 03:03 PM
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)
mcolton
06-25-2014, 03:20 PM
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
jscheuer1
06-25-2014, 03:23 PM
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:
<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:
<!DOCTYPE html>
Use it instead of:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
mcolton
06-25-2014, 03:25 PM
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
jscheuer1
06-25-2014, 03:30 PM
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).
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.