[Javascript] Same-named functions (was link onclick=location.href not working)

Peter Brunone peter at brunone.com
Tue Mar 30 11:47:38 CST 2004


> What I don't know
>is what would happen if you had 2 functions (one JS and one VB) by the same
>name. I'm too lazy to find out though :)

  Never say "what if" around me; you'll get either the answer or endless speculation.  In this case, I put together a small sample for IE6, and the result was a trip to Bizarro World.  Consider the following:

<form>
<input type="button" onclick="Gabooga()" value="Call VBScript Function"> &nbsp;
<input type="button" onclick="gabooga()" value="Call Javascript Function">
<br>
</form>
<script language="Javascript">
function gabooga() {
	alert("gabooga javascript");
	}
</script>

<script language="VBScript">
Function Gabooga
   alert("Gabooga VBScript")
End Function
</script>

   If you run this in IE, you get the exact opposite of what you would expect (the one calling the VBScript function actually calls the Javascript function, which would seem to be an impossibility due to the case sensitivity of the language.  Commenting out the VBScript function takes things back to normal, and the JS-triggering button throws an error.  Commenting out the JScript function allows both buttons to home in on the case-insensitive VBScript function.

   Case both buttons' function calls the same (lower-case g) and you'll STILL see them call different functions.  Isn't MS error-tolerance fun?

Cheers,

Peter

Original Message:
>From: "Chris T" <christ at saeweb.com>
>
>> Now if
>> folks start hanging VB script and other funky things off of event handlers
>> as a matter of regular course (and revised W3C standards), this might
>> someday change...
>
>VBScript works much in the same way, right? The event handler isn't
>neccessarily tied simply to JavaScript.
>
>Admittedly, I don't use VBScript all that much (if ever), so I may be
>mistaken, but an event is just that. It's not neccessarily a "JavaScript"
>event.  Scripting languages are interchanged easily enough to where you can
>call a JS function that in turn calls a VBScript function. What I don't know
>is what would happen if you had 2 functions (one JS and one VB) by the same
>name. I'm too lazy to find out though :)





More information about the Javascript mailing list