Reputation: 6221
I have a modal that is prepopulated with some text for the user to edit, with a limit of 500 characters. I wanted to include a 'remaining character' notification. I have it working for the onKeyUp, but I want it to initialize with how many characters are left (right now the span is empty until the user hits a key). Neither of the onLoad functions are working (maybe onLoad is wrong? Fairly new here). Any help is appreciated!
<div id="tooltip-modal" style="display:none">
<script language = "Javascript">
maxLength = 500;
var container = $("#tooltip_body");
function taCount(tooltipBody,Cnt) {
objCnt = createObject(Cnt);
objVal = tooltipBody.value;
if (objCnt) {
objCnt.innerText=maxLength-objVal.length;
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
onLoad="alert('Loaded')";
onLoad="return taCount(container,'myCounter')";
</script>
<body>
<form method="post" action="#" id="update-tooltip">
<h2>Edit the description of this item:</h2>
<input type="hidden" name="tooltip_id" id="tooltip_id">
<textarea onKeyUp="return taCount(this,'myCounter')" name="tooltip_body" id="tooltip_body" class="input" rows=7 wrap="physical" cols=40></textarea>
<br><br>
You have <strong><span id="myCounter" ></span></strong> characters remaining for your description...</h3><br>
<button type="submit" value="Update" id="update" >Update</button>
</form>
</body>
</div>
Upvotes: 0
Views: 137
Reputation: 58
Pretty sure that onload has to be tied to an element on the page, such as the body tag.
http://www.w3schools.com/jsref/event_onload.asp
Upvotes: 1