Skip to content

Instantly share code, notes, and snippets.

@jaysonrowe
Created October 31, 2011 02:27
Show Gist options
  • Select an option

  • Save jaysonrowe/1326776 to your computer and use it in GitHub Desktop.

Select an option

Save jaysonrowe/1326776 to your computer and use it in GitHub Desktop.
jQuery code for Textbox countdown
<script type="text/javascript">
<!--
$('#micropost_content').live('keyup keydown', function(e) {
var maxLen = 140;
var left = maxLen - $(this).val().length;
$('#char-count').html(left);
});
//-->
</script>
<%= form_for @micropost do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.text_area :content, :maxlength => 140 %>
</div>
<div>Characters left: <span id="char-count">140</span></div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment