Modify the href attribute of tag dynamically in WordPress

Question

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="https://na2.docusign.net/member/PowerFormSigning.aspx?PowerFormId=df6fbf3d-6f5d-4c48-8965-f4fa810099f4&amp;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','https://na2.docusign.net/member/PowerFormSigning.aspx?PowerFormId=df6fbf3d-6f5d-4c48-8965-f4fa810099f4&Institutional_Buyer_AnnualPrice=' + price);
         return false;
    }
})(jQuery);

Here is the link of the page: https://www.kuali.co/products/kuali-ready-online-purchasing/

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 wordpress.stackexchange.com

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="https://www.wptricks.com/question/modify-the-href-attribute-of-tag-dynamically-in-wordpress/">

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

Leave an answer