Label not associated to input












4















Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label tag to the input directly but I shouldn't have to do that.



Here is a code snippet that is created from Subscribe2



<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">


Can be found here: https://blog.collaborative.org/










share|improve this question

























  • Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

    – slugolicious
    Nov 28 '18 at 20:05











  • Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

    – slugolicious
    Nov 28 '18 at 20:07













  • The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

    – andrewmacpherson
    Nov 28 '18 at 20:09













  • Are the IDs unique? If there are two inputs with the same ID that could cause this.

    – andrewmacpherson
    Nov 28 '18 at 20:13











  • Sure, I had stripped it apart a little to simplify it. Will update OP.

    – Travis Johnston
    Nov 28 '18 at 20:14
















4















Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label tag to the input directly but I shouldn't have to do that.



Here is a code snippet that is created from Subscribe2



<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">


Can be found here: https://blog.collaborative.org/










share|improve this question

























  • Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

    – slugolicious
    Nov 28 '18 at 20:05











  • Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

    – slugolicious
    Nov 28 '18 at 20:07













  • The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

    – andrewmacpherson
    Nov 28 '18 at 20:09













  • Are the IDs unique? If there are two inputs with the same ID that could cause this.

    – andrewmacpherson
    Nov 28 '18 at 20:13











  • Sure, I had stripped it apart a little to simplify it. Will update OP.

    – Travis Johnston
    Nov 28 '18 at 20:14














4












4








4








Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label tag to the input directly but I shouldn't have to do that.



Here is a code snippet that is created from Subscribe2



<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">


Can be found here: https://blog.collaborative.org/










share|improve this question
















Using the built in Chrome Lighthouse to run accessibility audit on a WP site showed the signup field as being invalid due to no associated label. I've run into this before and I can't understand why it doesn't think it's associated. I can get it to pass by adding an aria-label tag to the input directly but I shouldn't have to do that.



Here is a code snippet that is created from Subscribe2



<label for="s2email">Your email:</label>
<br>
<input type="text" name="email" id="s2email" value="Enter email address..." size="20" onfocus="if (this.value === 'Enter email address...') {this.value = '';}" onblur="if (this.value === '') {this.value = 'Enter email address...';}">


Can be found here: https://blog.collaborative.org/







html accessibility html-form html-validation lighthouse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Jaap

395613




395613










asked Nov 28 '18 at 18:46









Travis JohnstonTravis Johnston

19110




19110













  • Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

    – slugolicious
    Nov 28 '18 at 20:05











  • Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

    – slugolicious
    Nov 28 '18 at 20:07













  • The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

    – andrewmacpherson
    Nov 28 '18 at 20:09













  • Are the IDs unique? If there are two inputs with the same ID that could cause this.

    – andrewmacpherson
    Nov 28 '18 at 20:13











  • Sure, I had stripped it apart a little to simplify it. Will update OP.

    – Travis Johnston
    Nov 28 '18 at 20:14



















  • Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

    – slugolicious
    Nov 28 '18 at 20:05











  • Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

    – slugolicious
    Nov 28 '18 at 20:07













  • The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

    – andrewmacpherson
    Nov 28 '18 at 20:09













  • Are the IDs unique? If there are two inputs with the same ID that could cause this.

    – andrewmacpherson
    Nov 28 '18 at 20:13











  • Sure, I had stripped it apart a little to simplify it. Will update OP.

    – Travis Johnston
    Nov 28 '18 at 20:14

















Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

– slugolicious
Nov 28 '18 at 20:05





Something is missing from your example. If I copy/paste your sample into a simple page, it passes lighthouse (and axe). The <label> correctly points to the <input>. I usually see problems when the <input> has a NAME attribute but not an ID attribute. That is, the <label> points to "s3email" but the <input> has name="s2email" (which is for javascript) and doesn't have id="s2email".

– slugolicious
Nov 28 '18 at 20:05













Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

– slugolicious
Nov 28 '18 at 20:07







Note also that your onfocus is pointing to a string instead of a function. That's another hint that you might have typed the code sample instead of copy/pasting the original code that has the problem. I'm assuming you don't really have an on handler pointing to a string.

– slugolicious
Nov 28 '18 at 20:07















The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

– andrewmacpherson
Nov 28 '18 at 20:09







The for/id relationship looks correct here. Can we see the actual page, to look at the whole context? Or, can you provide the exact report that the tool provided?

– andrewmacpherson
Nov 28 '18 at 20:09















Are the IDs unique? If there are two inputs with the same ID that could cause this.

– andrewmacpherson
Nov 28 '18 at 20:13





Are the IDs unique? If there are two inputs with the same ID that could cause this.

– andrewmacpherson
Nov 28 '18 at 20:13













Sure, I had stripped it apart a little to simplify it. Will update OP.

– Travis Johnston
Nov 28 '18 at 20:14





Sure, I had stripped it apart a little to simplify it. Will update OP.

– Travis Johnston
Nov 28 '18 at 20:14












1 Answer
1






active

oldest

votes


















1














When you look at the code sample in isolation, it looks fine: it has a label explicitly associated with the input element using the for and id attributes.



However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; } the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)



Note that display: none does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)






share|improve this answer
























  • Ahh that makes sense! I'll adjust that and test.

    – Travis Johnston
    Nov 29 '18 at 14:10












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526123%2flabel-not-associated-to-input%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














When you look at the code sample in isolation, it looks fine: it has a label explicitly associated with the input element using the for and id attributes.



However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; } the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)



Note that display: none does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)






share|improve this answer
























  • Ahh that makes sense! I'll adjust that and test.

    – Travis Johnston
    Nov 29 '18 at 14:10
















1














When you look at the code sample in isolation, it looks fine: it has a label explicitly associated with the input element using the for and id attributes.



However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; } the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)



Note that display: none does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)






share|improve this answer
























  • Ahh that makes sense! I'll adjust that and test.

    – Travis Johnston
    Nov 29 '18 at 14:10














1












1








1







When you look at the code sample in isolation, it looks fine: it has a label explicitly associated with the input element using the for and id attributes.



However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; } the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)



Note that display: none does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)






share|improve this answer













When you look at the code sample in isolation, it looks fine: it has a label explicitly associated with the input element using the for and id attributes.



However, when you inspect the site, it looks different: due to the style rule .s2_form_widget label { display: none; } the label is invisible. (You can see this when you use the Inspector in Firefox, move to the label in the DOM tree and check the associated styles.)



Note that display: none does not only hide the label visually but also for screen readers. As a result, the input element has no label from the point of view of a screen reader or another assistive technology and fails the requirement that form controls need explicit labels. (As an alternative, you might try hiding the label off-screen with a negative margin.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 29 '18 at 14:05









Christophe StrobbeChristophe Strobbe

1,38011023




1,38011023













  • Ahh that makes sense! I'll adjust that and test.

    – Travis Johnston
    Nov 29 '18 at 14:10



















  • Ahh that makes sense! I'll adjust that and test.

    – Travis Johnston
    Nov 29 '18 at 14:10

















Ahh that makes sense! I'll adjust that and test.

– Travis Johnston
Nov 29 '18 at 14:10





Ahh that makes sense! I'll adjust that and test.

– Travis Johnston
Nov 29 '18 at 14:10




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526123%2flabel-not-associated-to-input%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks