hello
Could you help me,anticipate thanks Jack
Here is my Javascript,and my questions:
Why the global variables in the to_do() function
(j and toto) can be used only in the to_do()
function,and when they are external to the to_do()
function,they are declared undefined ,what I have
to do to see these variables in the whole script?
Why in the to_do() function, if I call an other
function (myfonc() ),it's not work, but the
alert(" "
function works correctly ?
<html>
<head>
<title> essai </title>
</head>
<body>
<script language = "JavaScript">
var toto,j; // global
var streams = new Array();
streams[0] = new makeStream("","",""
;
streams[1] = new makeStream("1","11","table1"
;
streams[2] = new makeStream("2","22","table2"
;
function makeStream(name1,name2,name)
{
this.name1 = name1;
this.name2 = name2;
this.name = name;
}
function to_do(s)
{
toto = s.options[s.selectedIndex].value;
if(toto == "1"
{
document.write("TABLE1_fonction"
; // ok
j=1;
myfonc(); // not ok
}
if(toto == "2"
{
//document.write("TABLE2_fonction"
;
j = 2;
alert("toto"
; //ok
}
}
document.writeln('<SELECT NAME="streams" onChange="to_do(this)">');
document.writeln('<SELECT NAME="streams" onChange="faire(this)">');
document.writeln('<OPTION VALUE="', streams[0].name1, '">', streams[0].name);
document.writeln('<OPTION VALUE="', streams[1].name1, '">', streams[1].name);
document.writeln('<OPTION VALUE="', streams[2].name1, '">', streams[2].name);
document.writeln('</SELECT>');
myfonc(x)
{
document.write("j:",j);} // not ok, j undefined
document.write("toto:",toto); // not ok, toto undefined
}
document.write("toto:",toto); // not ok, toto undefined ?
</script>
</body>
</html>
Could you help me,anticipate thanks Jack
Here is my Javascript,and my questions:
Why the global variables in the to_do() function
(j and toto) can be used only in the to_do()
function,and when they are external to the to_do()
function,they are declared undefined ,what I have
to do to see these variables in the whole script?
Why in the to_do() function, if I call an other
function (myfonc() ),it's not work, but the
alert(" "
<html>
<head>
<title> essai </title>
</head>
<body>
<script language = "JavaScript">
var toto,j; // global
var streams = new Array();
streams[0] = new makeStream("","",""
streams[1] = new makeStream("1","11","table1"
streams[2] = new makeStream("2","22","table2"
function makeStream(name1,name2,name)
{
this.name1 = name1;
this.name2 = name2;
this.name = name;
}
function to_do(s)
{
toto = s.options[s.selectedIndex].value;
if(toto == "1"
{
document.write("TABLE1_fonction"
j=1;
myfonc(); // not ok
}
if(toto == "2"
{
//document.write("TABLE2_fonction"
j = 2;
alert("toto"
}
}
document.writeln('<SELECT NAME="streams" onChange="to_do(this)">');
document.writeln('<SELECT NAME="streams" onChange="faire(this)">');
document.writeln('<OPTION VALUE="', streams[0].name1, '">', streams[0].name);
document.writeln('<OPTION VALUE="', streams[1].name1, '">', streams[1].name);
document.writeln('<OPTION VALUE="', streams[2].name1, '">', streams[2].name);
document.writeln('</SELECT>');
myfonc(x)
{
document.write("j:",j);} // not ok, j undefined
document.write("toto:",toto); // not ok, toto undefined
}
document.write("toto:",toto); // not ok, toto undefined ?
</script>
</body>
</html>