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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.