
Originally Posted by
unemployment
Yes, but I want the character count displayed when the page loads.
You are misinterpreting what I said. Putting script commands at the end of the body allows you to run script command before the page load event occurs.
Let me try and get this idea across to you in a different way.
You need to run the script that updates the character count when the page loads. That means you need to run a script that triggers the update.
You have already attached an onkeyup event to the companydo element with the following command:
Code:
companydo.onkeyup = validate_companydo_field_length;
So you now need to trigger that onkeyup event when the page loads, which will allow the counter number to be updated.
The code you need to add in order to trigger that onkeyup event is:
Whether you run that triggering script from an onload event, or from the end of the body just before the </body> tag, or in some other way, it is the act of running that additional line of code that allows the character count to update.
I advise that you add that line of code to your script, and that you load your script from the end of the body.
Best practices: Put scripts at bottom
script.js
Code javascript:
var companydo = document.getElementById('cscompanydo');
// other code ...
companydo.onkeyup = validate_companydo_field_length;
companydo.onkeydown = validate_companydo_field_length;
companydo.onblur = validate_companydo_field_length;
companydo.onkeyup();
Code html4strict:
<body>
<!-- form stuff here -->
<script type="text/javascript" src="script.js">
</body>
</html>
Bookmarks