I
inigo.villalba
Hi,
I hope someone can point out my error because I'm starting to lose my
hair over this. It's probably a very straigh forward error but after
only 4 hours sleep it's doing my head in. It's to do with global
variables in Firefox 1.
The following code works no problems and generates a whole bunch of
numbers
<script type="text/javascript">
function createCal(){
var dateObj = new Date();
for(var i=0;i<32;i++){
date = dateObj.getDate();
set_date = dateObj.setDate(i);
document.write(date);
}
}
</script>
but when I try to place the dateObj variable outside the function (with
or without the preceding "var") it tells me dateObj is not defined.
Aren't variables declared outside of a function supposed to be global?
It all works fine in IE 5 btw
<script type="text/javascript">
var dateObj = new Date();
function createCal(){
for(var i=0;i<32;i++){
date = dateObj.getDate();
set_date = dateObj.setDate(i);
document.write(date);
}
}
</script>
Interestingly when I replace the document.write() with an alert
everything works as it should.
Thanks
barabis
I hope someone can point out my error because I'm starting to lose my
hair over this. It's probably a very straigh forward error but after
only 4 hours sleep it's doing my head in. It's to do with global
variables in Firefox 1.
The following code works no problems and generates a whole bunch of
numbers
<script type="text/javascript">
function createCal(){
var dateObj = new Date();
for(var i=0;i<32;i++){
date = dateObj.getDate();
set_date = dateObj.setDate(i);
document.write(date);
}
}
</script>
but when I try to place the dateObj variable outside the function (with
or without the preceding "var") it tells me dateObj is not defined.
Aren't variables declared outside of a function supposed to be global?
It all works fine in IE 5 btw
<script type="text/javascript">
var dateObj = new Date();
function createCal(){
for(var i=0;i<32;i++){
date = dateObj.getDate();
set_date = dateObj.setDate(i);
document.write(date);
}
}
</script>
Interestingly when I replace the document.write() with an alert
everything works as it should.
Thanks
barabis