<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Html on Jake Worth</title><link>https://jakeworth.com/tags/html/</link><description>Recent content in Html on Jake Worth</description><image><title>Jake Worth</title><url>https://jakeworth.com/twittercard.png</url><link>https://jakeworth.com/twittercard.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 24 May 2024 09:25:37 -0400</lastBuildDate><atom:link href="https://jakeworth.com/tags/html/index.xml" rel="self" type="application/rss+xml"/><item><title>Reading a Button's Value on Submit</title><link>https://jakeworth.com/tils/reading-a-buttons-value-on-submit/</link><pubDate>Fri, 24 May 2024 09:25:37 -0400</pubDate><guid>https://jakeworth.com/tils/reading-a-buttons-value-on-submit/</guid><description>&lt;p&gt;Complex HTML forms often end up with multiple submit buttons. Consider a form
for taxes: there&amp;rsquo;s a button to save a draft and another button to submit for
processing. They both trigger the submit action on the same form. How could we
accomplish this while keeping the buttons fairly simple?&lt;/p&gt;
&lt;p&gt;One solution is to set the buttons&amp;rsquo; value:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;form&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;onsubmit&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;{onSubmit}&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;&amp;lt;!-- Form fields here --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;input&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;type&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;submit&amp;#34;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;value&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;save&amp;#34;&lt;/span&gt; /&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;input&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;type&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;submit&amp;#34;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;value&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;submit&amp;#34;&lt;/span&gt; /&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;/&lt;span style="color:#f92672"&gt;form&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then in the submit handler, we read the value.&lt;/p&gt;</description></item><item><title>Autofocus a Form Field</title><link>https://jakeworth.com/tils/autofocus-a-form-field/</link><pubDate>Tue, 21 May 2024 10:50:17 -0400</pubDate><guid>https://jakeworth.com/tils/autofocus-a-form-field/</guid><description>&lt;p&gt;&lt;code&gt;autofocus&lt;/code&gt; is a global attribute that sets a field as focused on page load.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;input&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;name&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;first_name&amp;#34;&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;autofocus&lt;/span&gt; /&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;No JavaScript required!&lt;/p&gt;
&lt;p&gt;A use case could be a new customer form that an employee fills out multiple
times a day. By autofocusing the first name field, you could save that
employee thousands of clicks.&lt;/p&gt;
&lt;p&gt;Carefully consider user experience and accessibility before using this attribute.&lt;/p&gt;
&lt;p&gt;Docs: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus"&gt;https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>