Call input value within span

0

I have this line of code:

<input type="text" class="form-control" id="usado" placeholder="Quantidade" aria-describedby="basic-addon1">
<span class="input-group-addon" id="basic-addon1" onclick="usaEstoque(usado,<?php echo $arrDados['produto']; ?>)"><span class="glyphicon glyphicon-fire"></span></span>

I'm trying to get the value of the input and the value of the product id (this working on other buttons) in order to get the amount put into the input of the stock. In general, I'm trying to update the stock on the page itself.

I created the function in javascript to test:

function usaEstoque(usado,id){

  var qtdUsado = usado;
  var idProduto = id;
  alert(qtdUsado, idProduto)
};
    
asked by anonymous 29.09.2015 / 15:46

1 answer

1

Try this:

<input type="text" class="form-control" id="usado" placeholder="Quantidade" aria-describedby="basic-addon1">
<span class="input-group-addon" id="basic-addon1" onclick="usaEstoque(<?php echo $arrDados['produto']; ?>)"><span class="glyphicon glyphicon-fire"></span></span>

And in your role:

function usaEstoque(id){
    var qtdUsado = document.getElementById("usado").value;
    var idProduto = id;
    alert(qtdUsado + " - " + idProduto);
};

In the click call you do not need to pass the reference or id of the input in question if it does not change. If it's always the same, you can get it inside the function with document.getElementById() .

    
29.09.2015 / 16:08