Getting a value from a script variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amarqujo
    New Member
    • Apr 2009
    • 3

    #1

    Getting a value from a script variable

    Hi,

    I have this piece of code and I need to get the value of the variable 'filmus1" into the audioplayer line.

    Code:
    <p id="audioplayer_m">blabla</p>  
    <script type="text/javascript" language="JavaScript">
    function choosebox1()
    {
    var filmus="";
    var filmus1= "";;
    varNumber = <?php echo '"'.$i.'"'; ?>;
    for (k=0; k<varNumber; k++) {
          if(document.getElementById('CBT'+k).checked){
                if (filmus==""){
                filmus = filmus + (document.getElementById('CBT'+k).value);}else
                {filmus = filmus + "," + (document.getElementById('CBT'+k).value);}
    	}else {}
    }
    filmus1 = '"' + filmus + '"';
    AudioPlayer.embed("audioplayer_m", {soundFile: ([B]get the filmus1 value here[/B]), width: 400, autostart: "yes"});
    }
    </script>
    Thanks for any help.
    Last edited by Dormilich; May 1 '09, 12:34 AM. Reason: added [code] tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Code:
    AudioPlayer.embed("audioplayer_m", eval('({soundFile: "'+filmus1+'", width: 400, autostart: "yes"})'));
    I used eval to evaluate JSON object.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Why not use it directly (haven't tested, mind you)?
      Code:
      AudioPlayer.embed("audioplayer_m", {soundFile: filmus1, width: 400, autostart: "yes"});
      Does that not work?

      Comment

      • amarqujo
        New Member
        • Apr 2009
        • 3

        #4
        Worked like this

        Code:
        <p id="audioplayer_m">Play</p>  
        <script type="text/javascript" language="JavaScript">
        function choosebox1()
        {
        var filmus="";
        varNumber = <?php echo '"'.$i.'"'; ?>;
        for (k=0; k<varNumber; k++) {
              if(document.getElementById('CBT'+k).checked){
                    if (filmus==""){
                    filmus = filmus + (document.getElementById('CBT'+k).value);}else
                    {filmus = filmus + "," + (document.getElementById('CBT'+k).value);}
        	}else {}
        }
        AudioPlayer.embed("audioplayer_m", {soundFile: [B][U]eval("filmus")[/U][/B], width: 400, autostart: "yes"});
        }
                
        </script>
        Last edited by acoder; May 1 '09, 11:15 AM. Reason: Please use [code] tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Does it not work without the eval?

          PS. please use [code] tags.

          Comment

          • amarqujo
            New Member
            • Apr 2009
            • 3

            #6
            Does it not work without the eval?

            Nope, only with eval.
            Thanks,

            Comment

            Working...