I'm trying to get a variable (an array) from PHP to javascript.
I need to write to another frame then where the script is, and as far as I know, PHP isn't frame-aware, because it's serverside.
Is there any way to get the array from PHP to javascript?

Arjen.

    try to use a trick like this...
    look if this suite for your problem
    goodluck J@ystick_FI

    <?
    //script side init your php var or array
    //in this case
    $pass = "yes";
    ?>
    <HTML>
    <HEAD>
    <TITLE> Gestione Descrizioni Manuali </TITLE>
    <SCRIPT language="javascript">

    function check(val)
    {
    alert("value of php var is " + val);
    }

    </SCRIPT>
    </HEAD>
    <BODY bgcolor="#FFFFFF" onload="check('<?=$pass?>')">

    </BODY>
    </HTML>

      That doesn't seem to work for me.
      This is what I tried (in javascript that is):

      for (i=0, i <= 10, i++)
      {
      zet_om ( <?php $list[$i] ?>, <?php $i?>);
      }

      If I use <?php=$php_list[$i] or <?=$php_list[$i] I get an error, saying an unexpected '=' is encoutered. So I removed them.
      But javascript gets screwed after the '<?php' or '?>'.
      Is this a common problem, or am I doing something wrong?
      (still a newbie to this, you know :rolleyes: )

      Arjen.

        ....try to pass variables in this way

        for (i=0, i <= 10, i++)
        {
        zet_om ( '<?=$list[$i]?>', '<?=$i?>');
        }

        ..it sould work 😉😃 J@ystick_FI😃

          Thanks for the fast reactions!

          I still can't figure out what's wrong.
          So here's the whole code, maybe this way it makes more sense:


          <HTML>
          <HEAD>
          <TITLE>Untitled</TITLE>
          <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

          <SCRIPT type="text/javascript">
          var js_list=new array();

          function zet_om (waarde,teller);
          {
          js_list[teller]=waarde;
          document.writeln ("X");
          }

          </SCRIPT>

          </HEAD>
          <BODY>

          <?php
          for ($i=0; $i <= 10; $i++)
          {
          $list[$i]=$i;
          print ("$i<br>");
          }
          ?>

          <script language="JavaScript" type="text/javascript">
          for (i=0, i <= 10, i++)
          {
          zet_om ('<?=$list[$i]?>','<?=$i?>');
          document.writeln (i);
          }

          for (i=0,i<=10; i++)
          {
          alert('!!!!!!!!');
          document.write ("*");
          document.writeln ("test: "+js_list);
          }
          </SCRIPT>


          </BODY>
          </HTML>


          my editor (html-kit) now recognizes the part after '<?=' still as javascript, but I can't still get it to work correctly.
          More suggestions?

          Arjen.

            there where a few errors in your code..
            the way to do that is:

            <?php
            for ($i=0; $i <= 10; $i++)
            {
            $list[$i]=$i;
            }
            ?>

            <HTML>
            <HEAD>
            <TITLE>Untitled</TITLE>
            <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

            <SCRIPT type="text/javascript">
            js_list = new Array();

            function zet_om (waarde,teller) 
            { 
            	js_list[teller]=waarde; 
            }

            <? for ($i=0 ; $i <= 10 ; $i++)
            { ?>
            zet_om ('<?=$list[$i]?>','<?=$i?>');
            document.writeln(<?=$i?>);
            <? } ?>

            for (var i=0 ; i<=10 ; i++) 
            { 
            		document.writeln ("test: " + js_list[i]); 
            } 

            </SCRIPT>

            </HEAD>
            <BODY>

            </BODY>
            </HTML>

            ...now works fine
            😃 J@ystick_FI😃

              Thanks...!

              I will look at it mondaymorning. (then I'm back at work, with a PHP compatible server all for meself... 😃 )

              Arjen.

                Indeed, now it works! 😃

                Thank you very much...

                Arjen

                  Could you tell me what the difference is between '<?' and '<?php

                  As far as I know is '<?' the short-tag, and '<?php' the full-tag. And that it shouldn't make a difference if I use the full-tag instead of the short-tag. But in this script, I get an error on line 25 (" zet_om ('<?=$list[$i]?>','<?=$i?>'); ") if I replace '>?' with '<?php'.

                  ???

                  Arjen

                    Write a Reply...