jquery – How to change a link <a>according to an</a><select> <a>?</a>

Question:

I'm creating a price list for my website, and I need that when the person changes the payment cycle, the link <a> (CONTRACT) be changed to go to the cart.

Example: If the person selects the Monthly cycle, the link will change to:

http://meusite.com/carrinho.php?produto=1&periodo=mensal

If the person chooses Quarterly , the link will change to:

http://meusite.com/carrinho.php?produto=1&periodo=trimestral

If the person chooses Semester , the link will change to:

http://meusite.com/carrinho.php?produto=1&periodo=semestral

And if the person chooses Annual , the link will change to:

http://meusite.com/carrinho.php?produto=1&periodo=anual

EXAMPLE IN JSFiddle

Answer:

Dude I made some changes in your Fiddle to work take a look there. I found it a little confusing because you were already using the value of the combos options to control the writing of the value, so I had to create an attribute in the options called " data-opt " with the values ​​{M,T,S,A}. Another change I had to make was to put id in the links and in each select I created a data-link attribute to match each combo with its respective link.

It wasn't the most correct way to do it, but it's working.

Scroll to Top