By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Getting a value from a script variable

P: 3
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. <p id="audioplayer_m">blabla</p>  
  2. <script type="text/javascript" language="JavaScript">
  3. function choosebox1()
  4. {
  5. var filmus="";
  6. var filmus1= "";;
  7. varNumber = <?php echo '"'.$i.'"'; ?>;
  8. for (k=0; k<varNumber; k++) {
  9.       if(document.getElementById('CBT'+k).checked){
  10.             if (filmus==""){
  11.             filmus = filmus + (document.getElementById('CBT'+k).value);}else
  12.             {filmus = filmus + "," + (document.getElementById('CBT'+k).value);}
  13.     }else {}
  14. }
  15. filmus1 = '"' + filmus + '"';
  16. AudioPlayer.embed("audioplayer_m", {soundFile: (get the filmus1 value here), width: 400, autostart: "yes"});
  17. }
  18. </script>
Thanks for any help.
Apr 30 '09 #1
Share this Question
Share on Google+
5 Replies


dmjpro
100+
P: 2,476
Expand|Select|Wrap|Line Numbers
  1. AudioPlayer.embed("audioplayer_m", eval('({soundFile: "'+filmus1+'", width: 400, autostart: "yes"})'));
  2.  
I used eval to evaluate JSON object.
May 1 '09 #2

acoder
Expert Mod 15k+
P: 16,027
Why not use it directly (haven't tested, mind you)?
Expand|Select|Wrap|Line Numbers
  1. AudioPlayer.embed("audioplayer_m", {soundFile: filmus1, width: 400, autostart: "yes"});
Does that not work?
May 1 '09 #3

P: 3
Expand|Select|Wrap|Line Numbers
  1. <p id="audioplayer_m">Play</p>  
  2. <script type="text/javascript" language="JavaScript">
  3. function choosebox1()
  4. {
  5. var filmus="";
  6. varNumber = <?php echo '"'.$i.'"'; ?>;
  7. for (k=0; k<varNumber; k++) {
  8.       if(document.getElementById('CBT'+k).checked){
  9.             if (filmus==""){
  10.             filmus = filmus + (document.getElementById('CBT'+k).value);}else
  11.             {filmus = filmus + "," + (document.getElementById('CBT'+k).value);}
  12.     }else {}
  13. }
  14. AudioPlayer.embed("audioplayer_m", {soundFile: eval("filmus"), width: 400, autostart: "yes"});
  15. }
  16.  
  17. </script>
May 1 '09 #4

acoder
Expert Mod 15k+
P: 16,027
Does it not work without the eval?

PS. please use [code] tags.
May 1 '09 #5

P: 3
Nope, only with eval.
Thanks,
May 1 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.