Exchanging link as input text

1

I need to create a input of text that as I enter a quantity it changes the link of a button, but only a part of the link.

Ex :.

I have this link: link

I want that whenever the person places 1,2,3,4 ... in the input it changes the value "qty = 1" of the link that the person will click the below.

Is this possible?

    
asked by anonymous 08.07.2015 / 14:29

3 answers

3

Yes it is possible

You will use the change event to do this.

$(document).ready(function(){
    $("#qty").change(function(){
       val = $(this).val();
       newURL = "https://sterilair.vtexcommercestable.com.br/checkout/cart/add?sku=17&qty=" + val + "&seller=1&sc=1";
      // alert(newURL);
       $(".log").append("URL trocada para:<br>"+newURL+"<br>");
       $(".url").attr({href:newURL});
    });
});
.log{
  height: 400px;
  overflow: auto;
  border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><inputname="qty" id="qty" type="number" />

<a class="url" href="https://sterilair.vtexcommercestable.com.br/checkout/cart/add?sku=17&qty=1&seller=1&sc=1">UFL</a>

<div class="log"></div>

This way whenever the value of d is changed to URL will be changed to the amount entered

    
08.07.2015 / 14:58
1

Hello,

You can do this with jquery.

Ex:

Quantidade: <input type="text" name="qtd"><br>
<input id="botao" type="button" value="Go to Google" />

<script>
  $("#botao").click(function() {

     location.href= "https://sterilair.vtexcommercestable.com.br/checkout/cart/add?sku=17&qty="+ $("#qtd").val() +"&seller=1&sc=1"


  });
</script>

Note that depending on what is filled in the input box the jquery script will form the url.

    
08.07.2015 / 14:51
0

Good! I do not know if I understood your question well ... But anyway, I tried to respond anyway ...

Possible is! after all in the computer everything is possible until you prove the contrary .... Well, let's go to what matters.

Solution

HTML

 <head>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script></head><body><divid="div_do_link">
       <input type="text" name="input_quantidade" id="input_link"/>
       <!-- Ancora-->
      <a href="" id="ancora_link" >Link</a>
   </div>

script

    $("div#div_do_link #input_link").keyup(function(){
        var value = this.value;
        if(value){
             var link = "https://sterilair.vtexcommercestable.com.br/checkout/cart/add?sku=17&qty="+value+"&seller=1&sc=1";
            $('div#div_do_link a#ancora_link').attr('href',link); 
       }

  })
    
08.07.2015 / 15:18