Good evening!

Function:

function myFunction() { var name = $("#name").val(); var cost = $("#cost").val(); var tmp = "http://site.com/go/<?php echo $this->user->info->username ?>/?transaction=" + name + "&item=" + cost; var result = encodeURI(tmp); $("#tar1").html(result); $("#par1").html(result); console.log(result); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

How to insert the result of execution in a href?

Thanks for any help!

    1 answer 1

    jquery .attr () documentation

     function myFunction() { var name = $("#name").val(); var cost = $("#cost").val(); var tmp = "http://site.com/go/<?php echo $this->user->info->username ?>/?transaction=" + name + "&item=" + cost; var result = encodeURI(tmp); $("#tar1").html(result); $("#par1").html(result); return result; } $('#someId').attr('href', myFunction()); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a id="someId" href="">ссылка</a> 

    • Alas, but it does not work. Made by your example. - Anton Bogomolov
    • @SergeyPlaxin demonstrate what you did, everything should work, in my answer, if you click on "execute code", everything works. - Vyacheslav Danshin
    • I apologize - rechecked, missed the symbol. Your option works - thank you very much, you helped me a lot! And thanks for the reference to the documentation! - Anton Bogomolov