﻿// Maxlength Script
//  Accepts a control to act on and a maxlength
//  stops a user from entering any more characters
//  other than delete, backspace, right arrow, left arrow
//  when character length is >= maxlength
//
//  This is a workaround for maxlength not working in multiline mode
//
//  Call this way:  onkeydown="javascript:MaxLength(this);"

// Added Character Count function at end

function MaxLength(oObject, maxlen, charcounter)

{
var charcount = document.getElementById(charcounter);
if(charcount)
    charcount.value = "Char Count: " + oObject.value.length + "/" + maxlen;

if (oObject.value.length<maxlen)

return true;
else

{
if ((event.keyCode>=37 && event.keyCode<=40) || (event.keyCode==8) || (event.keyCode==46))

event.returnValue = true;

else
event.returnValue = false;

}

}

// CharCount Function
//  Accepts a control, maxlength and control id
//  Returns a string to the value of the control whose id
//  was passed in indicating how many characters are used 
//  over max characters allowed.
//
//  Call this way: onkeyup="CharCount(this,'1000','charcount')" 
function CharCount(oObject, maxlen, charcounter)

{
var charcount = document.getElementById(charcounter);
if(charcount)
    charcount.value = "Char Count: " + oObject.value.length + "/" + maxlen;
}
