2
I need to pass two parameters via url
and create a JS function to receive these parameters and place them at the source of a script.
Follow what I got.
Link to the parameters: <a href="<?php bloginfo( 'url' ); ?>/cotacao?id=17&fonte=Verdana">Dólar</a>
Function to pick the 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:
<!-- 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>
Error returned:
Image link: image
It would not be better if you declared these variables as global or put in a configuration object?
– André Ribeiro
Hello André, the way I did I can get the values, but I can not insert the variables in the script src. The result of the Alerts that are commented are: Alert(id) -> id=17 and Alert(source) -> source=Verdana... exactly what I need to put in the ID and FONTS places in src. Sorry I’m new to programming.
– Flávia Amaral
I get it. You has do this with javascript or you can use PHP to print these values in
src
?– André Ribeiro
@When you solve a question you created, create an answer and mark it as accepted. Here we do not put solved in the question nor the solution. It is a site of questions and answers. Thank goodness that solved your problem :)
– Jorge B.
Hi Jorge, thanks for the feedback.
– Flávia Amaral