WordPress.org

Ready to get started?Download WordPress

Forums

Execute a javascript from PHP (4 posts)

  1. camdizzle
    Member
    Posted 1 year ago #

    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.

  2. camdizzle
    Member
    Posted 1 year ago #

    <?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
    }
    ?>

  3. camdizzle
    Member
    Posted 1 year ago #

    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.

  4. 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 }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic