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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to pass javascript function variable into php

    Can anyone please teach me how do I get the 'count' from click.php and pass into the '$clicked' of clickcount.php ?

    Thank you so much for helping ^.^

    cllick.php

    PHP Code:
    <script type="text/javascript">

        var 
    count 0;
        function 
    countClicks() {
        
    count count 1;
        
    document.getElementById("clicks").innerHTML count;
        }
        
    </script> 
    clickcheck.php

    PHP Code:
    <?php

    $click 
    '?????'// I don't know how should i define this
        
    if(!isset($clicked) || empty($clicked)) {
                    die(
    "No click is counted.");
                    
    header = ('login3.php');
        
                    } else if (
    $clicked $content || $clicked $content){
                        die(
    "Click count(s) is not correct!");
                        
    header = ('login.php)';
                    } else {
                     die(
    "Login success.");
                     
    header = ('welcome.php');
                        }
        
    ?>

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    if your submitting a form you could load the javascript value in an input field.

  • #3
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    The only way for JavaScript, client-side, to interact with PHP, server-side, is through Ajax.

    There may be other, newer ways that I have not heard of, but Ajax would be my first go-to


  •  

    Posting Permissions

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