Jump to content

Character Counter OnLoad


unemployment

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/231798-character-counter-onload/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.