Write javascript in php using echo

Hi,

I want to write following javascript in my php script at server side.

<script language="javascript" type="text/javascript">
alert("Your message has been send successfully");
window.location.href="My-page.php?id=<?=$id?>";
</script>

I try following but not working

<?php

echo "<script language='javascript' type='text/javascript'>";
echo "alert('Your message has been send successfully');";
echo "window.location.href='My-page.php?id=".$id;
echo "</script>";

?>

Any idea?

-Thanks

What happens when you load the page? It should work. You named your page with “.php” right?

Now it is working.

echo "<script language='javascript' type='text/javascript'>";
echo "alert('Your message has been send successfully');";
echo "</script>";

$URL="page.php";
echo "<script>location.href='$URL'</script>";
1 Like