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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing values to javascript

    I have a page on which there will be a list of names.
    On another page, which is called via Javascript, I will have more information on that name selected.

    I am using the Wordpress standalone audioplayer on the second page.
    What I am looking at doing is, having PHP replace the selected name each time the second page is called.

    How would I code the link for starters?

    Then, how would I code the Javascript code line where the name will be replaced?

    Code:
    <script type="text/javascript">AudioPlayer.embed("audioplayer_1", {soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>
    This code appears on page two.

    I am attempting to streamline coding so that I don't have to code 10 seperate entries for each song name.

  • #2
    New to the CF scene
    Join Date
    Dec 2012
    Location
    Toronto, ON
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Suwannee_guy View Post
    I have a page on which there will be a list of names.
    On another page, which is called via Javascript, I will have more information on that name selected.

    I am using the Wordpress standalone audioplayer on the second page.
    What I am looking at doing is, having PHP replace the selected name each time the second page is called.

    How would I code the link for starters?

    Then, how would I code the Javascript code line where the name will be replaced?

    Code:
    <script type="text/javascript">AudioPlayer.embed("audioplayer_1", {soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>
    This code appears on page two.

    I am attempting to streamline coding so that I don't have to code 10 seperate entries for each song name.

    Hi ,

    I would suggest you to use sessions here.

    session_start();

    I believe when user selects a button on the first page you are using action listener in javascript

    Use session variables to keep tracking. You can always use <?=$_SESSION['vairablename'] ?> on the second page part of javascript.

    Use Reload function on the second page something like
    <input type="button" value="Reload 2nd Frame" onClick="window.parent.frames[0].location.reload();">


    Hope this helps,

    Nehal

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    PHP Code:
    <?php
    echo "<script type=\"text/javascript\">AudioPlayer.embed(\"audioplayer_1\"," .
        
    "{soundFile: \"http://mroldies.net/mp3/($value1}-{$value2}.mp3\"})</script>";
    ?>
    But where are $value1 and $value2 coming from? Presumably they are/could be $_GET variables passed to the page.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    Regular Coder
    Join Date
    Jun 2012
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the reply Andrew.
    that's kind of what I had figured on how to do it within that script.
    But how does value1 and value2 get passed from page to page?
    I am presuming somewhere in the link on page one I would assign them.
    Something like ?value1=name&value2=song ??

    But how exactly?

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Something like ?value1=name&value2=song ??
    Yes. So you might have a link in the first page:

    Code:
    <a href="otherpage.php?value1=name&value2=song">Go there!</a>
    using php or js to construct the parameters.

    In the second page:
    PHP Code:
    if (isset($_GET['value1']) && !empty($_GET['value1'])) {
        
    $value1 $_GET['value1'];
    }
    // similarly for value2. 
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

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