pass a variable to a url

Asked

Viewed 887 times

1

 $(document).ready(function () {
var codigo = "abC";
});
<a class="btn btn-default" href="/meuApp/pagina?codigo=" + codigo +  >Cancelar</a>

Good afternoon.

I’m breaking my head and I can’t pass a variable to a url .

It’s okay to use this:

 $(document).ready(function () {
var codigo = "abC";
});

And on the page I have the url :

<a class="btn btn-default" href="/meuApp/pagiba?codigo=" + codigo >Ver</a>

It doesn’t even open my qd page. What am I missing?

  • Your link is correct?

  • Yeah... I just can’t get that variable.

  • have tried using a "Document.write(code)"?

  • @Lucastorres I put in the url ?

  • First of an Inspection on the page and see if the code is being printed, if not, put a script tag after the same and try to do this. Test-only

1 answer

3


You cannot use the variable this way in your HTML, Javascript will not be interpreted within your HTML element.

You can do the following:

<a class="btn btn-default custom-url" href="#" >Ver</a>

     $(document).ready(function () {
        $('.custom-url').attr('href', '/meuApp/pagiba?codigo=SEUCODIGO');
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.