views:

88

answers:

2

Here is the situation:

I have one function which has local variable. I would like to assign that value to global variable and us it's value in another function.

Here is the code:

global_var = "abc";

function loadpages()
{
    local_var = "xyz";
    global_var= local_var;
}

function show_global_var_value()
{
    alert(global_var);
}

I'm calling show_global_var_value() function in the HTML page but it shows the value = "xyz" not "abc"

What am I doing wrong?

A: 

What do you want to achieve? Function loadpages changes value of global_var from "abc" to "xyz".

$ js
js> global_var = "abc";
abc
js> function loadpages() { local_var = "xyz"; global_var= local_var; }
js> function show_global_var_value() { print(global_var); }
js> show_global_var_value()
abc
js> loadpages()
js> show_global_var_value()
xyz
el.pescado
A: 

Yes, I want to change the value of the global variable value using function. The example about is just a concept of what I'm going to apply to my code.

Thanks Mike

Mike_NC