<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Rich Reuter - jquery</title>
    <link>http://www.richreuter.com/</link>
    <description>Music and Code from the Gem City</description>
    <language>en-us</language>
    <copyright>Rich Reuter</copyright>
    <lastBuildDate>Fri, 01 Aug 2008 18:04:22 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>rich@richreuter.com</managingEditor>
    <webMaster>rich@richreuter.com</webMaster>
    <item>
      <trackback:ping>http://www.richreuter.com/Trackback.aspx?guid=277f75d6-c407-42ad-81fd-608c46246d84</trackback:ping>
      <pingback:server>http://www.richreuter.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.richreuter.com/PermaLink,guid,277f75d6-c407-42ad-81fd-608c46246d84.aspx</pingback:target>
      <dc:creator>Rich Reuter</dc:creator>
      <wfw:comment>http://www.richreuter.com/CommentView,guid,277f75d6-c407-42ad-81fd-608c46246d84.aspx</wfw:comment>
      <wfw:commentRss>http://www.richreuter.com/SyndicationService.asmx/GetEntryCommentsRss?guid=277f75d6-c407-42ad-81fd-608c46246d84</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been spending a lot of time with <a href="http://jquery.com/">jQuery</a> lately
and have been really digging it. In fact, I'm doing a short grok talk on it for the <a href="http://daytondevgroup.net/">Dayton
.NET Developers Group</a> at the end of this month.
</p>
        <p>
Here's a short snippet I came up with to resize text boxes so that the width of the
textbox would be proportional to the maximum number of characters allowed by the maxlength
property on the textbox. It's not exact - through trial and error I figured out that
7.3 and 8 work as ratios for maxlength value to the corresponding width. That's based
on the font I'm using and the size of the textboxes (smaller ones seem to have a slightly
different ratio than larger ones). You'll probably have to tweak those values to get
what you need, but it's a start.
</p>
        <pre>
          <span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">$('<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">input</span>[type=text]').each(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">function</span>()
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> max_length <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> $(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>).attr('maxlength'); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> multiplier <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (max_length
&gt; 10) ? 7.3 : 8; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">var</span> w <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (max_length <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">*</span> multiplier) <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"px"</span>;
$(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>).width(w);
});</span>
        </pre>
        <br />
        <br />
        <img width="0" height="0" src="http://www.richreuter.com/aggbug.ashx?id=277f75d6-c407-42ad-81fd-608c46246d84" />
      </body>
      <title>Using jQuery to Resize TextBoxes to MaxLength</title>
      <guid isPermaLink="false">http://www.richreuter.com/PermaLink,guid,277f75d6-c407-42ad-81fd-608c46246d84.aspx</guid>
      <link>http://www.richreuter.com/2008/08/01/UsingJQueryToResizeTextBoxesToMaxLength.aspx</link>
      <pubDate>Fri, 01 Aug 2008 18:04:22 GMT</pubDate>
      <description>&lt;p&gt;
I've been spending a lot of time with &lt;a href="http://jquery.com/"&gt;jQuery&lt;/a&gt; lately
and have been really digging it. In fact, I'm doing a short grok talk on it for the &lt;a href="http://daytondevgroup.net/"&gt;Dayton
.NET Developers Group&lt;/a&gt; at the end of this month.
&lt;/p&gt;
&lt;p&gt;
Here's a short snippet I came up with to resize text boxes so that the width of the
textbox would be proportional to the maximum number of characters allowed by the maxlength
property on the textbox. It's not exact - through trial and error I figured out that
7.3 and 8 work as ratios for maxlength value to the corresponding width. That's based
on the font I'm using and the size of the textboxes (smaller ones seem to have a slightly
different ratio than larger ones). You'll probably have to tweak those values to get
what you need, but it's a start.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;$('&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;input&lt;/span&gt;[type=text]').each(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;function&lt;/span&gt;()
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; max_length &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; $(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;).attr('maxlength'); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; multiplier &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (max_length
&amp;gt; 10) ? 7.3 : 8; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var&lt;/span&gt; w &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (max_length &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; multiplier) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"px"&lt;/span&gt;;
$(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;).width(w);
});&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img width="0" height="0" src="http://www.richreuter.com/aggbug.ashx?id=277f75d6-c407-42ad-81fd-608c46246d84" /&gt;</description>
      <comments>http://www.richreuter.com/CommentView,guid,277f75d6-c407-42ad-81fd-608c46246d84.aspx</comments>
      <category>coding</category>
      <category>jquery</category>
    </item>
  </channel>
</rss>