Q1.
As to onload, and a variety of other things, using a framework like jQuery (my favorite) is best. It simplifies things a lot.
But with or without something like that, you need to ask yourself if you even need to wait until onload. Usually you do not. Usually the parsing by the browser of the element(s) you want to alter is all you need before you can do what you want with them.
If that's the case, scrap body onload and place the inits or whatever in a script block just before the closing </body> tag:
Code:
<script type="text/javascript">
initListGroup('vehicles', document.forms[0].make, document.forms[0].type, document.forms[0].model, 'cs');
initListGroup('houses', document.forms[1].make, document.forms[1].type, document.forms[1].model, 'cs');
</script>
</body>
</html>
Q2.
There are a number of correct ways to call one element's event from another. And I said that if this is done reciprocally, it will probably end up in an endless loop. That's because one element will call the other, which will then call the first, and back again, and on and on. So are you asking how to call one element's event from another, or how to get two elements to do the same thing onchange (the latter should be obvious)?
To call one element's event from another do:
Code:
<select onchange="whatever.onchange.call(whatever);"
where whatever is a reference to the element that has the onchange event that you want to run. If there are arguments place them like so:
Code:
<select onchange="whatever.onchange.call(whatever, arg1, ar2);"
To get two elements to do the same thing onchange, simply give them both the same onchange event. Include in the function for that event all that you want to have happen.
Added Question
To call a form element within a particular form, since all elements on a page that have an id should have a unique id, you may use the ById method. But if you want to use the document.forms collection and work off of the name of the form element which now only needs to be unique within the form, do:
Code:
document.forms['name'].elements['elementName']
Bookmarks