unemployment Posted March 26, 2011 Share Posted March 26, 2011 How can I make my character counter display how many characters are left on page load. Right now it only displayed the number of characters left when I user keysup, keysdown or onblurs. [HIGHLIGHT=JavaScript] var companydo = document.getElementById('cscompanydo'); function validate_companydo_field_length() { var len = companydo.value.length; var mc = 2000; if (len > mc) { companydo.value = companydo.value.substring(0,mc); len = mc; } document.getElementById('doremaining').innerHTML = mc - len; } companydo.onkeyup = validate_companydo_field_length; companydo.onkeydown = validate_companydo_field_length; companydo.onblur = validate_companydo_field_length; [/HIGHLIGHT] [HIGHLIGHT=HTML4Strict] <textarea class="medium mediumwidth man" id="cscompanydo" name="companydo" rows="" cols=""><?php echo $answer['companydo']; ?></textarea> <div class="f_right mts mrs"><span id="doremaining" class="mrs">2000</span>characters remaining</div> [/HIGHLIGHT] Quote Link to comment https://forums.phpfreaks.com/topic/231798-character-counter-onload/ Share on other sites More sharing options...
RichardRotterdam Posted March 26, 2011 Share Posted March 26, 2011 window.onload = function() { // do something when the page has been loaded. } I prefer domready using a framework though. Quote Link to comment https://forums.phpfreaks.com/topic/231798-character-counter-onload/#findComment-1192625 Share on other sites More sharing options...
unemployment Posted March 26, 2011 Author Share Posted March 26, 2011 window.onload = function() { // do something when the page has been loaded. } I prefer domready using a framework though. The thing is... I already have it wrapped around an addonload function, so i'm not sure why the character counter value isn't being recognized onload. Quote Link to comment https://forums.phpfreaks.com/topic/231798-character-counter-onload/#findComment-1192626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.