S
Safalra
The problem below is obviously some sort of namespace clash, but I don't
understand exactly why - can anyone explain? Take the following simple
Javascript code:
<script type="text/javascript">
function scrollLeft(){ alert('scrollLeft') };
function scrollLeft2(){ alert('scrollLeft2') };
scrollLeft();
scrollLeft2();
</script>
This pops up two alert boxes saying 'scrollLeft' and 'scrollLeft2' as you
would expect. However, if you then add a couple of buttons calling these
functions:
<form><div>
<input type="button" value="scrollLeft" onClick="scrollLeft();">
<input type="button" value="scrollLeft2" onClick="scrollLeft2();">
</div></form>
....then the button calling scrollLeft doesn't work - Firefox's Javascript
Console says 'ScrollLeft is not a function'. What I don't understand is
that if scrollLeft is already defined somewhere automatically (the only
other code on the page is the minimal necessary HTML), why did the call to
the function inside the <script> element work?
understand exactly why - can anyone explain? Take the following simple
Javascript code:
<script type="text/javascript">
function scrollLeft(){ alert('scrollLeft') };
function scrollLeft2(){ alert('scrollLeft2') };
scrollLeft();
scrollLeft2();
</script>
This pops up two alert boxes saying 'scrollLeft' and 'scrollLeft2' as you
would expect. However, if you then add a couple of buttons calling these
functions:
<form><div>
<input type="button" value="scrollLeft" onClick="scrollLeft();">
<input type="button" value="scrollLeft2" onClick="scrollLeft2();">
</div></form>
....then the button calling scrollLeft doesn't work - Firefox's Javascript
Console says 'ScrollLeft is not a function'. What I don't understand is
that if scrollLeft is already defined somewhere automatically (the only
other code on the page is the minimal necessary HTML), why did the call to
the function inside the <script> element work?