Microsoft KB Archive/152981

= PRB: Placement of  Tag Results in Unexpected Behavior =

Article ID: 152981

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Visual Basic, Scripting Edition 1.0
 * Microsoft Visual Basic, Scripting Edition 1.1
 * Microsoft Visual Basic, Scripting Edition 2.0

-



This article was previously published under Q152981



SYMPTOMS
Microsoft Internet Explorer supports both JavaScript and VBScript functionality. For compatibility reasons, the default is JavaScript. If a block of  code is placed ahead of a block of code, errors may result.



RESOLUTION
To prevent these errors, always place tags ahead of any objects that call into functions defined with the tags. By moving the tag and associated code ahead of the form definition, the VBScript compiler is invoked and the Button element correctly references the function it calls in the onClick event.



STATUS
This behavior is by design. Internet Explorer 3.0 defaults to JavaScript compilation.



MORE INFORMATION
As an HTML page containing VBScript or JavaScript, code is loaded by Internet Explorer 3.0, it is parsed and compiled. If a form element makes a call to some function that is later defined within a tag, errors can result if the form element does not use the proper calling conventions.

Internet Explorer 3.0 defaults to using the JavaScript compiler. When the compiler sees the form element, it generates JavaScript code to make the function call associated to the form element. If the tag is defined after the form element and specifies Language="VBScript," this function call is syntactically incorrect and an error results.

To avoid this error, all tags should be defined before any form or other objects that make functions calls. The preferred placement of the tag is within the  tags. By using this placement, any function that may be called by a forms element has already been loaded and compiled.

Steps to Reproduce Behavior
The following HTML code demonstrates the problem:   a test 



 sub btnPress alert "you pressed the button" end sub  Because the compiler reads the form definition first, it compiles the onClick event into a JavaScript reference. When the button is clicked, the interpreter tries to find the appropriate JavaScript function to execute. However, the function is in a block of VBScript code and is not seen by the interpreter as executable JavaScript code. Therefore, an "object doesn't support the property or method" error results.

Additional query words: kbdse kndsi vbscript vbs

Keywords: kbscript kbfaq KB152981

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.