Mário Correia Mário Correia - 6 months ago 13
HTML Question

document.title funcion can't set it work with php

I have this line of code

<script type="text/javascript">
document.title = "<?php include('pot1.php');?>"
</script>


My pot1.php gives me an echo with one random number, but that code does not seem to work and I don't know why the echo doesn't appear in my title. Is anything wrong with the code?

pot1.php code:

<?php
@include_once('link1.php');
$cg = fetchinfo("value","info","name","current_game");
$cb = fetchinfo("cost","games","id",$cg);
$cb=round($cb,2);
echo '$'.$cb;
?>


This echo is working and is giving me values because I can see them in one div.

Answer

You should just do it like this:

<?php include('pot1.php');?>

Now we know that there is a variable set. Echo that into the title tag.

<script type="text/javascript">
    document.title = "<? echo $cb ?>"
</script>

The way you're doing it now... I don't think you can include an entire PHP page and expect to behave like a simple string, even if that's all it returns.