Show variable in script src

2

I need to pass two parameters via url and create a JS function to get these parameters and place them in the source of a script.

Follow what I already have.

Link to the parameters: <a href="<?php bloginfo( 'url' ); ?>/cotacao?id=17&fonte=Verdana">Dólar</a>

Function to get parameters:

<script>
                    var url   = window.location.search.replace("?", "");
                    var items = url.split("&");
                    var array = {
                      'id' : items[0],
                      'fonte' : items[1]
                    }
                    var id = array.id;
                    var fonte = array.fonte;
                    //alert(id);
                    //alert(fonte);
                </script>

Script where the id and source variables should come from:

<!-- Widgets Notícias Agrícolas - www.noticiasagricolas.com.br/widgets -->
 <script type="text/javascript" src="http://www.noticiasagricolas.com.br/widget/cotacoes.js.php?ID&FONTE&tamanho=10pt&largura=500px&cortexto=333333&corcabecalho=B2C3C6&corlinha=DCE7E9&imagem=true&output=js"></script>

Errorreturned:

Link image: image

    
asked by anonymous 21.01.2015 / 14:28

1 answer

2

Solution: I changed the entire function for an echo, adding $ _GET where I want.

 <?php echo "<script type='text/javascript' src='http://www.noticiasagricolas.com.br/widget/cotacoes.js.php?id=".$_GET['id']‌​."&tamanho=12pt&cortexto=333333&corcabecalho=B2C3C6&corlinha=DCE7E9&imagem=true&o‌​utput=js'></scrit>"; ?>
    
21.01.2015 / 18:29