WordPress.org

Support

Support » How-To and Troubleshooting » Execute a javascript from PHP

Execute a javascript from PHP

  • camdizzle

    @camdizzle

    From what I’ve read this should be possible but I need a little support to get it going.

    I want a user to put their linkedin username into a field, then call that field from the table, please that field into the javascript below for $linkedinvariable and run the javascript.

    Now, I know that PHP is Server Side and Javascript is Client Side, but I want to run it within a php IF statement. IF LINKEDINFIELD is empty then “message” else run code below.

    <script src=”//platform.linkedin.com/in.js” type=”text/javascript”></script>
    <script type=”IN/MemberProfile” data-id=”http://www.linkedin.com/in/$LINKEDINVARIABLE” data-format=”inline”></script>

    I egarly await a response from the pros.

Viewing 3 replies - 1 through 3 (of 3 total)
  • camdizzle

    @camdizzle

    <?php
    $linkedin = $curauth->linkedin;
    if (empty($linkedin)) {
    echo ‘Update your profile and include your linkedin ID’;
    } else {
    JAVASCRIPT HERE, BUT HOW TO I PROPERLY DISPLAY IT FOR EXECUTION
    }
    ?>

    camdizzle

    @camdizzle

    I believe I’ve worked out the Javascript execution however I cant seem to get the variable to work within the javascript. Your assistance is greatly appreciated.

    Chris Olbekson

    @c3mdigital

    Level 12 Bug Squasher & Forum Moderator

    If you want to use a php variable in javascript you have to wrap it in php tags and echo it.

    <?php
    $linkedin = $curauth->linkedin;
    if (empty($linkedin)) {
    echo 'Update your profile and include your linkedin ID';
    } else { ?>
    <script>
    javascript:alert("<?php echo $linkedin; ?>");
    </script>
    <?php }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Execute a javascript from PHP’ is closed to new replies.