Is this realy all and everything? I do not see any DOCTYPE declaration. Nor anything about what <script> is going to do, but that last remark may be because I do not know much about programming with Java.
In any case, with this combination of service side and client side scripting, I would check what was send from the server to the client/browser. And thus I would look in the code the browser got (often called page source or something like that).
But my main advice was to look in the browser what the code is it gets. That will remove all speculation about what the server made or did. You want to know what happens on the client, thus look (and show us) what the client has got and what it has to act on.
And btw, when you changed the original code that you posted (you saying you added a DOCTYPE declaration), why do you not show the code as it is now. We are not clairvoyant.
I am sorry I started talking about that DOCTYPE. It has most probably nothing to do with your problem, I only wanted to inform you that either you did not post the complete text, or that you miss things that should be there to create a correct HTML document. The statement you added now is next to worthless. But let us forget about it.
I repeat, my main effort is to let you look at the code as it arrives in your browser/client. After all, you say that your browser, for some reason does not execute the <script> coding you think that is in it. Thus we (you, I, others with Java knowledge) must see what the browser gets from the server… I now ask this for the third time! When you do not understand this, please say so (and then include what browser you use, else we are spending again a lot of lost asking/answering time).
I repeat, you/I/we are not realy interested in what is done in the server (as you say, that there are signs that that is correct). We want to know what the code looks in the browser, after the PHP script is executed and created the HTML page.
agunet74 wrote:
>
> I have a simple program:
>
> Code:
> --------------------
>
> <html>
> <head>
> <title>
> Display numbers and alerts
> </title>
> </head>
> <body>
> <?php
> for ($i=1;$i<=5;$i++){
> echo $i." <br>
";
> ?>
> <script>
> var num = “<?php echo $i; ?>” ;
> document.alert("num: " + num);
> </script>
> <?php
> }
> ?>
> </body>
> </html>
> --------------------
>
>
> The problem is that the numbers on the browser are displayed but the
> alerts don’t.
>
> Anybody has any clue what is happening here ?
>
> Thanks in advance for any feedback
>
> Regards,
>
> agunet74
>
>
No PHP . Pure JavaScript
<html>
<head>
<title>
Display numbers and alerts
</title>
</head>
<body>
<script>
var i=0
for (i=1;i<=5;i++){
document.writeln(i+"<br\>");
window.alert("num: " + i);
}
</script>
</body>
</html>