Hello,

I am building a program in PHP. I need to display a dynamic alert box, based off a dynamic report. I have found a way to incorporate a jscript variable into the alert box, so I need one of 2 things.

1, a way to define the jscript variable as the definition of the php variable

or

2, a way to incorporate the php variable into the alert box.

Thanks for any help,
Johnie Karr

    You can use php to print out the javascript required, writing the php variables as javascript variables, but I'm not aware of any way to link javascript with php as one is server-side and the other is client-side.

    Maybe ajax?

      ajax? Never heard of it.....cept the cleaner! lol
      Johnie

        that is an interesting idea crazychris.....using php to print out the javascript...I'll try that and post results..but not today

          Do you want to do something like this?

          <html>
          <head>
          <title> test </title>
          </head>
          <script language="javascript">
          
          function displayAlert(val)
          {
          	alert(val);
          }
          </script>
          <BODY>
          <?php
          $passingStr="pass this php variable to javascript function";
          print "<script language=\"javascript\">";
          print "displayAlert('".$passingStr."');";
          print "</script>";
          ?>
          </body>
          </html>
          

            Or even just

            <?php
            $passingStr="pass this php variable to javascript function";
            ?>
            <html>
            <head>
            <title> test </title>
            </head>
            <script language="javascript">
            
            function displayAlert(val)
            {
                alert(val);
            }
            </script>
            <BODY>
            <script language="javascript">
            displayAlert('<?php echo $passingStr?>');
            </script>
            </body>
            </html> 

            🙂

              Weedpacket wrote:

              Or even just

              <?php
              $passingStr="pass this php variable to javascript function";
              ?>
              <html>
              <head>
              <title> test </title>
              </head>
              <script language="javascript">
              
              function displayAlert(val)
              {
                  alert(val);
              }
              </script>
              <BODY>
              <script language="javascript">
              displayAlert('<?php echo $passingStr?>');
              </script>
              </body>
              </html> 

              🙂

              That is what I want, I didn't know I could open php inside the javascript.
              Thanks,

                Write a Reply...