Modify the href attribute of tag dynamically in WordPress


Im using Calculated Form Fields plugin for a WordPress website. I already created the form I needed, but now I need to add the calculated price from the form as a URL parameter dynamically, when the button bellow the form is clicked.

The website uses Visual Composer and this is the button html:

<a class="nectar-button medium accent-color has-icon regular-button" target="_blank" href=";Institutional_Buyer_AnnualPrice=15000"><span>Purchase Kuali Ready</span></a>

I want to change the “Institutional_Buyer_AnnualPrice=15000” part of the URL to be added/changed dynamically, according to what is the price in the field. And this is my current JavaScript code:

(function($) {
    document.getElementsByClassName("nectar-button").onclick = function() {
        var link = document.getElementsByClassName("nectar-button");
        var price = $('#fieldname9_1').val();
        link.setAttribute('href','' + price);
         return false;

Here is the link of the page:

I`ve already tried the solutions of like 3-4 questions about the same topic I found on Stackoverflow, but none of them works for me, thats why I wrote the question to

p.s. Please ignore the fact that making the js code work will affect all the buttons created with Visual Composer for now.


>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="">

Modify the href attribute of tag dynamically in Wordpress</a>
, Todor Atanasov 3 years 0 Answers 51 views 0

Leave an answer