Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts

    possible use php in javascript ?

    E.G. we can use html in php like

    PHP Code:
    <?php echo ' <!--HTML codes-->' ?>
    is it possbile to use php in javascript ?

    Code:
    <script language="javascript">
    function example(){
    //php codes
    }
    </script>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You can have php write things into the javascript, but you can't have javascript parse/execute php.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by zodehala View Post
    Code:
    <script language="javascript">
    function example(){
    //php codes
    }
    </script>
    Add after posting: sorry I missunderstand the question!!!

    yes is possible, php generate the page on the server after browser request but before the browser see what is in that page,

    best regards
    Last edited by oesxyl; 12-23-2007 at 11:14 PM. Reason: missunderstand the question

  • #4
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by zodehala View Post
    E.G. we can use html in php like

    PHP Code:
    <?php echo ' <!--HTML codes-->' ?>
    is it possbile to use php in javascript ?

    Code:
    <script language="javascript">
    function example(){
    //php codes
    }
    </script>
    these two are totally different..
    the first echo's html tags from a php script
    the second uses javascript to try to execute php

  • #5
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    It depends what u want ur script to do,

    If we want to insert any data into sql or want to display then usually i use

    Code:
    window.location = ....php;
    and then use redirection after sql query

    If u want to change anything then use ajax

    There is no direct way to do it but u can work around these things

  • #6
    Regular Coder
    Join Date
    Dec 2007
    Posts
    269
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thindrakhya View Post
    It depends what u want ur script to do,

    If we want to insert any data into sql or want to display then usually i use

    Code:
    window.location = ....php;
    and then use redirection after sql query

    If u want to change anything then use ajax

    There is no direct way to do it but u can work around these things
    for example define COOKIE or ragister in mySQL dB

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You can do it behind the scenes with AJAX. That way information gets sent to PHP and back without the user really knowing.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •