|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Javascript variable scope
Hi, guys
How can I change the global varaible's value in a function like <script language="JavaScript"> var color_bg; function changeBgColor(color) { color_bg= color; window.location.reload(); } </script> |
|
#2
|
||||
|
||||
|
That's what you are doing here? You've defined color_bg globally and then changed it?
__________________
selwonk If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more! |
|
#3
|
||||
|
||||
|
the scope of color_bg = color is limited to the function in this case. You'd have to redefine the value associated with the var color_bg outside of the function in order for its value to be changed globally.
__________________
If you found a post of mine helpful, please click on the on my post to add to my reputation.
|
|
#4
|
||||
|
||||
|
Quote:
but once the command window.location.reload(); is executed, the window is being... (surprise!) reloaded and the variable lose its value. you don't have, can't have, something like session variables in client side code!! |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Javascript variable scope |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|