ellenjones6
12-31-2019, 09:48 PM
When I do a Google Lighthouse mobile audit on any of my web pages, I get dinged under accessibility for something in the Google search box I use on every page.
Here is the web page I did an audit on: https://wildadirondacks.org/adirondack-butterflies-mourning-cloak-nymphalis-antiopa.html (https://wildadirondacks.org/adirondack-butterflies-mourning-cloak-nymphalis-antiopa.html)
The failing element has to do with form elements on the internal site search box: "Form elements do not have associated labels."
The problem is apparently with this line of code:
<input name="qfront" type="text" style="width: 70%">
I got this about script four or five years ago from JavaScriptKit.com. Here is the link: http://www.javascriptkit.com/script/script2/google_site_search.shtml
Here is my code, as I adapted it for my purposes
<script>
// Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use
//Enter domain of site to search.
var domainroot="wildadirondacks.org"
function Gsitesearch(curobj){
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
</script>
<section class="searchSection">
<form action="https://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">
<input name="q" type="hidden" />
<input name="qfront" type="text" style="width: 70%">
<input type="submit" value="" style="border-style: none; background: url('images/Search-Icon-1.png') no-repeat; width: 24px; height: 20px">
</form>
<h6>*</h6>
</section>
The search seems to work just fine, but I don't know Javascript at all; and I have no idea how to address Google's accessibility concerns by adding a label. Since this part of my web page is tucked away in a little include file, I would only need to make the necessary code change once.
So how to I add a label, without messing up how the search works? Please help!
Thanks ellen
Here is the web page I did an audit on: https://wildadirondacks.org/adirondack-butterflies-mourning-cloak-nymphalis-antiopa.html (https://wildadirondacks.org/adirondack-butterflies-mourning-cloak-nymphalis-antiopa.html)
The failing element has to do with form elements on the internal site search box: "Form elements do not have associated labels."
The problem is apparently with this line of code:
<input name="qfront" type="text" style="width: 70%">
I got this about script four or five years ago from JavaScriptKit.com. Here is the link: http://www.javascriptkit.com/script/script2/google_site_search.shtml
Here is my code, as I adapted it for my purposes
<script>
// Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use
//Enter domain of site to search.
var domainroot="wildadirondacks.org"
function Gsitesearch(curobj){
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
</script>
<section class="searchSection">
<form action="https://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">
<input name="q" type="hidden" />
<input name="qfront" type="text" style="width: 70%">
<input type="submit" value="" style="border-style: none; background: url('images/Search-Icon-1.png') no-repeat; width: 24px; height: 20px">
</form>
<h6>*</h6>
</section>
The search seems to work just fine, but I don't know Javascript at all; and I have no idea how to address Google's accessibility concerns by adding a label. Since this part of my web page is tucked away in a little include file, I would only need to make the necessary code change once.
So how to I add a label, without messing up how the search works? Please help!
Thanks ellen