Can i pass value to javascript from php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BigZero

    Can i pass value to javascript from php

    Hello,

    i need to pass some variables or value to javascript from php script.
    well all i need to pass to value to javascript that is with in same
    php file the two values r in php i need to pass it to javascript from
    there to ext page the following code make clear

    Code:
    <?php
    $ip = "192.168.1.5";
    $key = "xxxx";
    //javascript that takes two value and post to next frame
    <script language="JavaScript">
    function load(ip,key)
    {
    parent.rtop.location.href ='updata.php';
    //alert("the update loaded");
    parent.right.location.href ='show.php?ips='+ip+':'+key;
    //return true;
    }
    </script>
    here how can i call that javascript from php code.


    Thanks
    VM
  • Michael Fesser

    #2
    Re: Can i pass value to javascript from php

    ..oO(BigZero)
    >i need to pass some variables or value to javascript from php script.
    You can use PHP to print out the JavaScript code with whatever variables
    you like. But that's all.
    >here how can i call that javascript from php code.
    Remember when and on which sides of the connection PHP and JS run.

    Micha

    Comment

    • BigZero

      #3
      Re: Can i pass value to javascript from php

      thanks for reply,
      but i told u both r on same page.



      Thanks
      VM

      Comment

      • Erwin Moller

        #4
        Re: Can i pass value to javascript from php

        BigZero schreef:
        Hello,
        >
        i need to pass some variables or value to javascript from php script.
        well all i need to pass to value to javascript that is with in same
        php file the two values r in php i need to pass it to javascript from
        there to ext page the following code make clear
        >
        Code:
        >
        <?php
        $ip = "192.168.1.5";
        $key = "xxxx";
        //javascript that takes two value and post to next frame
        <script language="JavaScript">
        	function load(ip,key)
        	{
        parent.rtop.location.href ='updata.php';
        	//alert("the update loaded");
        parent.right.location.href ='show.php?ips='+ip+':'+key;
        //return true;
        }
        </script>
        >
        >
        here how can i call that javascript from php code.
        >
        >
        Thanks
        VM
        Hi,

        <?php
        $myVar = "Hello JavaScript";
        ?>
        <script type="text/javascript">
        alert('<?php echo $myVar; ?>');
        </script>

        So simply place the values you need at the right place in your output.
        Remember that PHP only produces the source for the browser.
        So you simply do a 'view source' in your browser to see what PHP produced.

        If you need JavaScript to get values from PHP without a pagereload, use
        AJAX.

        Regards,
        Erwin Moller

        Comment

        • BigZero

          #5
          Re: Can i pass value to javascript from php

          Thanks,it works thanks again,
          one more thing every one talking about AJAX what is it and do u have
          any samples for that,



          Thanks
          VM

          Comment

          • Michael Fesser

            #6
            Re: Can i pass value to javascript from php

            ..oO(BigZero)
            >thanks for reply,
            >but i told u both r on same page.
            Correct, but both are executed at different times and in different
            environments (PHP on the server, JS on the client).

            Micha

            Comment

            • Erwin Moller

              #7
              Re: Can i pass value to javascript from php

              BigZero schreef:
              Thanks,it works thanks again,
              one more thing every one talking about AJAX what is it and do u have
              any samples for that,
              >
              Hi,

              Ajax is a way of letting JavaScript fetch things from URLs without a
              pagereload.

              This is a nice place to start:
              Sorry! We can't seem to find the resource you're looking for


              Regards,
              Erwin Moller
              >
              >
              Thanks
              VM

              Comment

              • BigZero

                #8
                Re: Can i pass value to javascript from php

                Thanks





                VM

                Comment

                • Satya

                  #9
                  Re: Can i pass value to javascript from php

                  On May 24, 12:18 pm, BigZero <vijaymajagaon. ..@gmail.comwro te:
                  Thanks
                  >
                  VM
                  and i have written a complete article for this kind of query.
                    About This blog has moved to www.satya-weblog.com. Thank You!

                  Comment

                  Working...