Hey, i have a wierd snippet i've written that embeds javascript in PHP and then PHP in the javascript. I was just wondering if this can be done. Anyway.. here is it:

if ($_SERVER['HTTP_REFERER']=="http://www.scarredforlife.co.uk/ForumReplies?threadid=$threadid&sectionid=$sectid") {
	echo "<script>";
	echo "var message = document.form1.replymessage.value;";
	echo "document.writeln('<?php $_SESSION[message]=' + message + '?>'";
	echo "</script>";
}

Any more questions, just ask...

Many thanks, BIOSTALL

    yes you are able to produce javascript code with php. i think the one place you have a problem is
    echo "document.writeln('<?php $_SESSION[message]=' + message + '?>'";

    should be

    echo "document.writeln('{$_SESSION['message']}')";

      Ok, thanks...

      Well, what if i was to do something like this:

      echo "document.writeln('".$_SESSION['message']=." + message')";

      ???

      Thanks 🙂 BIOSTALL

        the = sign after $_SESSION['message'] will give a parse error since you are in an echo. and where is the javascript message variable coming from? php cant get a javascript variable like that since it wont exist til the page finishes loading in the persons browser.

          Soooo.. how do you suggest i get around this?? :-S

          Perhaps:

          echo "document.writeln('".$_SESSION['message']." + '=' + message')"; 
          

          ??

          Read my first post about where the javascript 'message' is coming from 🙂

          BIOSTALL

            if you want to assign something from javascript to php, you have to make a new call to a php script passing the javascript variable in the query string.

              Write a Reply...