Digital Farmer
Digital Farmer

Reputation: 2107

Change href value in button after choose in a selector

I tried to set the button's link from the querySelector, but the value doesn't change, how do I get it set that way?

The idea is to change the button's link when I select the value in a dropdown box so I can click and open the link.

My attempt:

select_1
    .on("change", function(d) {
    var value_1 = d3.select(this).property("value");
    document.querySelector('#botao-de-jogo-betfair-1').href = value_1;
    });

The button:

<button class="button" style="width: 100%;" id="botao-de-jogo-betfair-1" href="link selector" target="_blank">Jogo Betfair 1</button>

When I use it in the way with <a I'll put it below, the value changes but it gets really weird with the link value inside the button, I'd like to just leave the button:

<button class="button" style="width: 100%;" ><a id="botao-de-jogo-betfair-1" href="link selector" target="_blank">Jogo Betfair 1</a></button>

Upvotes: 0

Views: 139

Answers (1)

vanowm
vanowm

Reputation: 10201

<button> doesn't have a href property, so you'll need change it's href attribute:

select_1
    .on("change", function(d) {
    var value_1 = d3.select(this).property("value");
    document.querySelector('#botao-de-jogo-betfair-1').setAttribute("href", value_1);
    });

Upvotes: 2

Related Questions