how to do variable or echo on a javascript?

Discussion in 'JavaScript' started by chonghua, Aug 18, 2009.

  1. #1
    	<script type="text/javascript" charset="utf-8"><!--
    	tfb.account = "{$accountlist}";
    	tfb.label = "follow-us";
    	tfb.color = "#35ccff";
    	tfb.side = "l";
    	tfb.top = 136;
    	tfb.showbadge();
    	--></script>
    Code (markup):
    im echoing $accountlist so i can insert my said account name on that particular script.. how to do it?

    thanks
     
    chonghua, Aug 18, 2009 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi,
    if the variable $accountlist is formatted as JSON (e.g. $accountlist = "member:'value',member1:'value'";), you can simply write:
    tfb.account = "{<?php echo $accountlist ?>}";
    Just keep in mind that the page needs to be .php...
     
    lp1051, Aug 18, 2009 IP
  3. chonghua

    chonghua Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    variable $accountlist is on php.. like:

    $accountlist = mybb=>settings <-- just an example of the code

    how to write on javascript so i can change any echo for it.. thanks
     
    chonghua, Aug 19, 2009 IP
  4. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Hi, I'm sorry, but I'm not sure what do you mean...
    This should be : $accountlist = $mybb->settings;
    But how do you want to change echo on javascript???
    You could use function json_encode() to get JSON string from the 'settings' array you have, and then access it in javascript e.g. via tfb.account.name, but I'm not really sure if it is what you want...
    Can you explain more clearly your intentions?
     
    lp1051, Aug 19, 2009 IP
  5. chonghua

    chonghua Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i think my problem was solve when i make a variable to determine it on php.. before i have set the javascript on my template.. it works if i make a function via php..
    anyway, thanks a lot! :p ill post again here whenever i have a problem.. thanks

    
    	$accountlist = $mybb->settings['xxx_account'];
    
    	<script type=\"text/javascript\" charset=\"utf-8\"><!--
    	tfb.account = \"{$accountlist}\";
    	tfb.label = \"{$xxx}\";
    	tfb.color = \"#35ccff\";
    	tfb.side = \"{$xxx}\";
    	tfb.top = {$xxx};
    	tfb.showbadge();
    	--></script>";
    
    
    Code (markup):
     
    chonghua, Aug 19, 2009 IP