legal ECMA-262 octal constant

JavaScript related questions should go here.
Post Reply
janvier123
Posts: 23
Joined: Tue Apr 17, 2012 6:25 am

legal ECMA-262 octal constant

Post by janvier123 »

The error Message:
[syntax=javascript]
SyntaxError: 08 is not a legal ECMA-262 octal constant
[/syntax]


I try to put (int), but its does not seem to help, and sins i dont know allot about java, ill just post it here :)
Any help would be welcome tho ;)

The code:
[syntax=php]<?php
$hour = (int)date("H", time());
$min = (int)date("i", time());
$sec = (int)date("s", time());
?>[/syntax]
[syntax=javascript]<script type="text/javascript">
function clockon(hour, min, sec) {
hours= hour
minutes= min
seconds= sec
seconds++;
if (seconds==60) {
seconds = "0";
minutes++;
}
if (minutes==60) {
minutes = "0";
hours++;
}
if (hours==24) hours = "0";
if (eval(hours)<10) {hours="0"+hours}
if (eval(minutes)<10) {minutes="0"+minutes}
if (eval(seconds)<10) {seconds="0"+seconds}
document.getElementById('txtTime').innerHTML= hours + ":" + minutes + ":" + seconds;
setTimeout("clockon("+hours+","+minutes+","+seconds+")",1000);
}
</script>
<span name='txtTime' id='txtTime'></span><br><?php echo date("F d, Y", time())?>
<script>clockon('<?php echo $hour; ?>', '<?php echo $min; ?>', '<?php echo $sec; ?>')</script>[/syntax]
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: legal ECMA-262 octal constant

Post by bowersbros »

In javascript, numbers with a leading zero are not considered to be correct, when used in the way you use them.

There are different types of numbers, for example binary ,decimal, octal and hexadecimal.

Octal doesn't allow leading zeros. keep them in the form of decimal to carry out calculations on them.

[syntax=javascript]if (hours==24) hours = "0";[/syntax]

That might also cause an issue. Try changingg it to { }

[syntax=javascript]setTimeout("clockon("+hours+","+minutes+","+seconds+")",1000);[/syntax]

Im not too sure what your trying to do there. But it isn't right, because your calling that within the function, which I believe will cause it to loop indefinately.

[syntax=javascript] hours= hour
minutes= min
seconds= sec[/syntax]

Why not just pass them in as hours, minutes and seconds then there is no need to do this.

[syntax=javascript]minutes="0"+minutes[/syntax]

I believe doing this will make it think that you want to add a string to an integer, which you can't do.Not 100% sure on that.

Anyway. I think the main part where your issue is, is with the setTimeout area.
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
janvier123
Posts: 23
Joined: Tue Apr 17, 2012 6:25 am

Re: legal ECMA-262 octal constant

Post by janvier123 »

Thx i didnt know that ;-)
ill play with it and see if i can fix it myself with your info ;)
Post Reply