• Resolved charismaarts

    (@charismaarts)


    Hello: I am trying to have a javascript thing where they press one button and one button from shortcode appears, and press another button and a second button appears; i have tested it all up to this point:
    I have gotten the javascript to work with the two buttons; and it switches text when you toggle between the two buttons; and I am using php to “echo” the text on the two options…

    so – I thought I should be able to just “echo do shortcode” and have the two shortcode buttons load on page instead of just echoing text…

    but i cannot get the shortcodes to work…

    here is the script:

    <script>
    function myFunction1b()
    {
    x=document.getElementById(“cars_level2”); // Find the element
    x.innerHTML = ‘<?php echo do_shortcode(‘[add_to_cart item=”e001″ ]’); ?>’;
    }
    </script>

    I dont know if you can echo do_shortcode in this code this way; but I am hoping; I am sure my coding is wrong; can anyone help with this? thanks…

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can’t do that. The JavaScript only runs in the browser, and PHP only runs in the server. By the time the JavaScript runs, PHP is no longer available.

    An easier method is to use PHP to put all the buttons you’ll need in the page at the start, using CSS to hide the stuff you don’t want the user to see. Then you can use JavaScript to reveal things and hide other things in the browser.

    Thread Starter charismaarts

    (@charismaarts)

    Thanks so much Rod; using what you suggested I was able to make this work!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘help with javacript and php’ is closed to new replies.