Js. There is a variable, and you need to put it in the link for the GET request. I can not understand how this can be implemented ?? Google is silent. The code (the second property on a GET request) is set using PHP. Click on the button - +1 to the number - the number in the link has changed, another click - +1 to the number, etc. As a result, the link should change dynamically in the process. There is code that comes in PHP. And there is a JS variable. They both need to be stuck in the link.

<p align="center"><a href="logfirst.php?kod= <?php echo $kod ?> &nrub=*ПЕРЕМЕННАЯ*"... 

Thank you in advance.

Closed due to the fact that the essence of the question is not clear to the participants of the Grundy , Dmitriy Simushev , user194374, cheops , zRrr Jun 30 '16 at 13:30 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What did you ask Google? What have you tried to do? Which link? - Gino Pane
  • I asked exactly what you have. Once again: for a GET request. /index.php?code=877&nrub=*variable * Well, either for the anchor ... - Alexander Andryushin
  • one
    You still didn't ask anything concrete :) What is the usage scenario? Why JS? Should the link dynamically change during the work? What does it depend on? Maybe you don't need JS here at all. The correct question is half the answer. - Gino Pane
  • the link is a string, but the lesson on working with lines is codebra.ru/ru/lessons-javascript/types/7/1 - Ordman
  • @GinoPane And so, in order ... JS because the script should be executed directly on the page (click on the button - +1 to the number - the number in the link has changed, another click - +1 to the number, etc.) In consequence , the link should change dynamically in the process. - Alexander Andryushin

2 answers 2

  1. Give the link an id.
  2. Then from the js-script, grab this link by its id and change the href property to what you need.
 document.getElementById('a_id').href = some_url 

UPD: Everything, I understand what your difficulty. You cannot simply replace the link, because there is a piece in it that occurs only at the moment of page generation, and JS does not know about it. So, you need to make JS know about it.

I see two ways.

First: It is only valid if your JS code is written on the page itself. You need to substitute $ kod not into the link itself, but inside the JS script, so that it ends up in some variable:

 <SCRIPT> js_kod = <?php echo $php_kod ?> </SCRIPT> 

After that, in the js-script you use this js-variable to substitute it into the link along with the second variable (which is for nrub).

The second method is less elegant. In it, before replacing the link, you extract the "code" from it, and use it when creating a new link.

  • Hmmm ... I forgot to tell you that the code (the second property on a GET request) is set in PHP. And how to be ((?? ?? Alexander Andryushin
  • one
    insert the value <? = $ param?> into the script? - Ordman
  • 2
    @Alexander Andrewin, you can always edit your question by adding all the necessary information to it - Grundy
  • If the link is generated when the page is received, and then does not change, then this is not even a question for PHP, it is just a trivial action. Use {$ param} - Xander
  • @ Alexander If it was generated at the time of receiving the page, my question would not have arisen - Alexander Andryushin

Thank you all for your help! If it were not for you, it would not have come to me that the variable can simply be taken and transferred! var kod = '<? echo $kod ?>'; Thank you all so much for your support!