 <p>Use <a href="http://api.jquery.com/val/" rel="nofollow"><code>.val()</code></a>, not <a href="http://api.jquery.com/attr/" rel="nofollow"><code>.attr()</code></a>, to set an element's value.</p> <p><a href="http://jsfiddle.net/mattball/jjjSf/" rel="nofollow">http://jsfiddle.net/mattball/jjjSf/</a></p> <hr> <p>As a side note, that's not remotely how <code>.attr()</code> — or JavaScript as a language — works. You cannot use a function call on the left-hand side of an assignment statement. It is meaningless.</p>