Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2008, 01:24 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 Oh, it happens this same way in ASP pages.

The order of execution is really weird. Try this code, for example:

That is a "documented feature". I believe the order is: script blocks in non-default language then script in <% %> delimiters then script blocks in default language. Can't remember exactly, fortunately I haven't had to do classic ASP for many years...

--

Joe (Microsoft MVP - XML)
 
Old September 17th, 2008, 09:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

This is not classic ASP - it's .NET 2005. Not using <% %> to designate VBscript either, just regular script tags. But scripts in either language are interspersed in the html because they are being generated by the page code behind based on the current page's validation requirements. Most are called by events when order of execution doesn't seem to be influenced by the scripts' order on the page. I've made a mental note of this for future reference, though.

Which language is considered the "default" script language in .NET?
 
Old September 17th, 2008, 01:33 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

> Which language is considered the "default" script language in .NET?

Non-sequitir.

As you pointed out, this is strictly a client-side issue.

In MSIE, the "default" script language is whichever one is declared first in the page. If neither is specified, then JavaScript is assumed.

You can prove this easily:
Code:
**** demo1.html****
<form>
<input type=button value="demo" onclick="if ( true ) { alert('JS'); }">
</form>
*******************

**** demo2.html****
<script language="VBScript">
Dim foo : foo = "whatever"
</script>
<form>
<input type=button value="demo" onclick="if ( true ) { alert('JS'); }">
</form>
*******************

**** demo3.html****
<script language="JavaScript">
var bar = "something";
</script>
<script language="VBScript">
Dim foo : foo = "whatever"
</script>
<form>
<input type=button value="demo" onclick="if ( true ) { alert('JS'); }">
</form>
*******************
demo2 won't even compile, much less run. Because MSIE "understands" that you are using VBScript as the default language for this page and of course the JS used in the onclick is syntactic nonsense in VBS.

You can make demo2 work by adding a language attribute to the button, thus:

<input type=button value="demo" language="javascript" onclick="if ( true ) { alert('JS'); }">

Note that demo3 works just fine, because the *first* script tag encountered has established JavaScript as the default language for the page.
 
Old September 17th, 2008, 01:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Not sure "non sequitor" applies here, but I assumed joefawcett was talking about the order of precedence in CLIENT based code. Do his comments apply only to CLASSIC ASP where script ran on the server, then?
 
Old September 17th, 2008, 02:20 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yes, Joe was commenting on ASP. I guess he was telling why my ASP-based demo turned out the way it did.

There must be some sort of similar rule in MSIE, but I haven't tried to work it out. There are obviously only two things involved in the browser, since there is no equivalent to the <%...%> tags.

Given the fact that the demo2 that I showed there doesn't even compile, I'd bet strongly that the order is "process all code involving default language first and then process the other language." Where default is defined as I showed it to be: Whichever is encountered first in the page.
 
Old September 17th, 2008, 02:35 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Just tried some experiments.

Mixing script languages in the browser does not behave at all as do ASP pages. The various script segments are execute (not sure about compiled...didn't go that deep) in the exact order they are encountered on the page. So it's a much simpler model than with ASP. Or much more complicated, if you think about what the poor browser has to do to make it all work right.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run a .js file from a javascript function sbkumar Javascript How-To 1 July 11th, 2008 11:12 AM
passing empty parameters to a js function crmpicco Javascript How-To 0 September 20th, 2005 10:16 AM
use a JS-variable/function inside a tag cybermaarten Javascript 3 January 20th, 2005 05:42 AM
function in linked js file 'is not defined' John K. King Javascript 4 May 7th, 2004 09:04 PM
Trigger a JS function on loss of focus apd8x Javascript 1 July 14th, 2003 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.