<?
$aa=array{"a","b","c");
?>
<script language=javascript>
functiontest()
{
varr p =new array();
p=$aa
</script>
question is How do I use the value of $aa within the java script?

    <?php
    $aa = array("a", "b", "c");
    ?>
    <script language=javascript>
    functiontest()
    {
       varr p = new array('<?php
    echo implode("', '", $aa);
    ?>')
    }
    </script>
    
      <?php
      $aa = array("a", "b", "c");
      ?>
      <script type='text/javascript'>
      function test()
      {
         var p = new array('<?php echo implode("', '", $aa); ?>')
      }
      </script>

      First off, it's var, not varr... secondly, it's function test, not functiontest, and thirdly, use type='' not language='' which is now becoming depreciated.

      Kind regards,
      Scott

        Hooray! The spelling police have arrived!

        Seriously, though, your comment about using "type" instead of "language" is correct (though probably non-critical). The rest are pretty obviously typos, which I propogated via a lazy copy-and-paste (and we all know that the best programming patterns are discovered by lazy programmers, right? 😉 ), as my intention was to show the actual PHP solution, not a complete code review of an obviously hastily written example.

          NogDog wrote:

          Hooray! The spelling police have arrived!

          Seriously, though, your comment about using "type" instead of "language" is correct (though probably non-critical). The rest are pretty obviously typos, which I propogated via a lazy copy-and-paste (and we all know that the best programming patterns are discovered by lazy programmers, right? 😉 ), as my intention was to show the actual PHP solution, not a complete code review of an obviously hastily written example.

          Oh mate,

          That post was not directed at you at all! It was more for the other guy. I understood you had just copied and pasted it and threw in the php ;-)

          I was just correcting it for the other guy so no worries mate.

          Kind regards,
          Scott

            It's deprecated, not depreciated

              Lol,

              That voids me as being the "Spelling Police" ;-)

              Kind regards,
              Scott

                5 days later

                [<?php
                $aa = array("a", "b", "c");

                ?>
                <script type='text/javascript'>
                function test()
                {
                var p = new array('<?php echo implode("', '", $aa); ?>')
                alert(p);
                }
                </script>
                <?
                test();
                ?>
                I did nt get the value of p?why?

                  You need to be careful when you switch back and forth between languages. You are using PHP to create Javascript. First the PHP runs on the server, it creates the Javascript and sends it to the client. Once the PHP has finished creating the Javascript and sending it to the client side, then the Javascript code can run. Since you've created a Javascript function, it won't run on it's own, you have to invoke it somehow. This could be the click of a button (use onclick) or it could be as the page loads (use <body onload>).

                  I think you just need to change this:

                  <?
                  test();
                  ?>

                  to this:

                  <body onload="Javascript:test();">
                    Write a Reply...