[RESOLVED] Calling a function onLoad? (JS)
How do you call a function when a text box is loaded? The onload event only applies to the body tag, framesets and other upper level stuff so that doesn't work.
<textarea name="criteria_2" style="width:98%;height:300px;margin-bottom:5px;"
onKeyup="updateWords(this,'limit_2',500);" onload="updateWords(this,'limit_2',500);">
Basically what is does is this. There's a textarea (this) and a corresponding textbox for it called limit_1. When the contents of the textarea changes, it alters the contents of limit_1. This all works fine but not when the page loads as limit_1 just stays blank. I can just do similar calculations on the server-side and then just alter the value="" attribute for limit_1, but I'd rather do it all on the client-side if possible.
I think you can see from the code what I'm trying to achieve.
[895 byte] By [
Nibinaear] at [2007-11-20 4:56:06]

# 1 Re: [RESOLVED] Calling a function onLoad? (JS)
You are making this too hard on yourself. Remember that, just like server-side scripts, JavaScript loads the page in order. In other words, if line 4 is loaded that means that lines 1 through 3 are as well.
Therefore...
<textarea name="criteria_2" style="width:98%;height:300px;margin-bottom:5px;"
onKeyup="updateWords(this,'limit_2',500);" id="criteria_2">
<script language="JavaScript">
var obj = document.getElementById('criteria_2');
updateWords(obj, 'limit_2', 500);
</script>
# 3 Re: [RESOLVED] Calling a function onLoad? (JS)
I did consider that you know!
Thought you might have. :wave: Have fun with the rest and good luck! :thumb: