Click to See Complete Forum and Search --> : variable scope


gokyo
04-29-2003, 08:50 AM
Hi everyone,
I got a stupid problem, I got a file .js call regSemplice.js where I put my function, I declared a global variable called tipoConto like that:

//Global
var tipoConto="";

I got a function... I call this function from an html page

function apriPianoConti(contoDareAvere){

//I do that
tipoConto = contoDareAvere;

//then
window.open(window.open("frmPianoConti.jsp", "_blank")

}

From the new window (frmPianoConti) I call a function that is in the same .js file...

function selectConto(nrConto){

//I wanna to test tipoConto variable and said me that tipoConto is undefined...
window.alert(tipoConto);

The question is WHYYYYY?


Any suggestion?

Thank's
ALohA

pyro
04-29-2003, 08:55 AM
I think you are going to need to do it more like this:

window.open(window.open("frmPianoConti.jsp?"+tipoConto+"", "_blank")

and, in the popup...

window.alert(window.location.search.substr(1));

Basically, what you will be doing is sending the value of tipoConto to frmPianoConti.jsp via the query string, where you can then strip it off using window.location.search.

gokyo
04-29-2003, 09:19 AM
Originally posted by pyro
I think you are going to need to do it more like this:

window.open(window.open("frmPianoConti.jsp?"+tipoConto+"", "_blank")

and, in the popup...

window.alert(window.location.search.substr(1));

Basically, what you will be doing is sending the value of tipoConto to frmPianoConti.jsp via the query string, where you can then strip it off using window.location.search.

well sorry pyro but I didn't understand very well what u meant, but anyway, can u explain me why tipoConto declared ad global dosn't keep the value during the lifetime? If I put a global variable in other language I can use it from any function or method he keep the value...

pyro
04-29-2003, 09:59 AM
The global variable will keep it's value in the same page, but will not keep it when you are working in different pages. One other option to reference this variable would be

alert(window.opener.tipoConto);

gokyo
04-29-2003, 10:11 AM
Ok pyro I got it now, thank's

ALohA