Skip to content

Instantly share code, notes, and snippets.

@niczak
Created November 7, 2011 01:42
Show Gist options
  • Save niczak/1343979 to your computer and use it in GitHub Desktop.
Save niczak/1343979 to your computer and use it in GitHub Desktop.
Check field length, replace text and alert user
$(document).ready(function() {
// bind function to event
$("#description").keyup(function()
{
// store value
var description = $("#description").val();
// check length
if(description.length > 244)
{
// grab substr
var replace = description.substr(0,244);
// replace value
$("#description").val(replace);
// alert user
alert("Maximum length for description reached.");
// return yo
return;
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment