Evan said:
I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...
<script>
function divControl(divName){
divName.innerHTML="test"
}
</script>
in the HTML I have three div's
<div id="test1"></div>
<div id="test2"></div>
<a onclick="divControl('test1')">test3</a>
The system does not seem to recognize the divName in the function ?!?!
Any help would be greatly appreciated
You're not passing an object. You're passing a string
containing the id of an object. That string does not
have an innerHTML attribute.
You can either pass a reference to the object, or you can
try to obtain a reference to the object in the function:
<script type="text/javascript">
function divControl(divName){
var divRef=document.getElementById(divName);
divRef.innerHTML="test"
}
</script>
In a production script, there should be error checking, too.