Click to See Complete Forum and Search --> : multiple <SCRIPT> </SCRIPT> tags


jitseschaafsma
06-17-2003, 04:14 AM
I have a js function optellen
<SCRIPT LANGUAGE=javascript>
var totsum=0

function optellen(var1)
{
totsum+=var1
}
</SCRIPT>
as you can see what it does it increase a global variable with var1.

Now my server generates a html page with a number of records. One of the values is stored in [FMP-Field:Cummuren]
Because i want to add up these values of the different records is use the following code in my HTML

<SCRIPT LANGUAGE=javascript> optellen([FMP-Field:Cummuren]) </script>
This works great because at the end of the page :
<SCRIPT LANGUAGE=javascript> document.write(totsum) </script>
Give the correct result.

(* i know there can be other solutions but because of limitations on my server side this is what i have chosen for *)

Now my question is this:

1] I am not sure if this will work for different browser : i mean when generating multiple <script> tags do i not lose my global variable in certain cases.

2] is the <script> functioncall </script> "theoreticall correct"

Thanks for any suggestion
Jitse

Gollum
06-17-2003, 04:32 AM
You can have as many nonoverlapping pairs of <script></script> tags as you like. They all share the same global scope.

jitseschaafsma
06-17-2003, 04:36 AM
thanks that is a relief
Jitse

Charles
06-17-2003, 04:36 AM
1) Your "global" variables are really properties of the Window object and can be referenced from any "script" block on the page.

2) <script> functioncall </script> is invalid HTML. Use instead <script type="text/javascript">functionCal()</script>.

3) Do keep in mind hat 13% of users do not use JavaScript and among that number are some disabled persons who cannot use JavaScript enabled browsers. You need to make sure that the page will work when JavaScript is absent.