www.webdeveloper.com
Results 1 to 4 of 4

Thread: php in javascript function

  1. #1
    Join Date
    Jun 2013
    Location
    Richmond, VA
    Posts
    6

    php in javascript function

    I want to reverse the order of the table but don't know how to put php in the function. Here's what I have:

    <html>
    <head>
    <script>

    function reverse()
    {
    /* HOW DO I GET PHP IN HERE? */
    }

    </script>


    </head>

    <body>
    <?php
    $w="A";
    $x="B";
    $y="C";
    $z="D";
    ?>

    <table style="border:1px solid black;">
    <tr>
    <td><?php echo "$w";?></td>
    </tr>
    <tr>
    <td><?php echo "$x";?></td>
    </tr>
    <tr>
    <td><?php echo "$y";?></td>
    </tr>
    <tr>
    <td><?php echo "$z";?></td>
    </tr>
    </table>


    <button onclick="reverse()">Reverse Order</button>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2011
    Posts
    1,140
    You don't need PHP. JavaScript's sort function can be used to do a descending sort. Try searching on "javascript sort".
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    9
    As rtrethewey says, you don't need PHP. But, anyway you can't insert php in JavaScript because php is server-side and JavaScript is client-side. This means that php runs BEFORE the page has been sent to the browser, and JavaScript AFTER that.

  4. #4
    Join Date
    Jun 2013
    Location
    Richmond, VA
    Posts
    6
    THanks for the info, both replies were very helpful!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles