Calling input value within span

Asked

Viewed 585 times

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 take the input value and the product id value (this working on other buttons), in order to remove the quantity placed in the stock input. In general lines, I am trying to update the stock on the page itself.

I created the javascript function to test:

function usaEstoque(usado,id){

  var qtdUsado = usado;
  var idProduto = id;
  alert(qtdUsado, idProduto)
};
  • What do you mean specifically with 'update the stock on the page'? You access the bank to give UPDATE or this update is only in memory with Javascript?

  • Access to the bank. I already have a trial ready for this, I’m just locking in time to get the data to pass to JS function.

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 job:

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 catch it inside the function with the document.getElementById().

  • I thought there should be some kind of Ubmit to get the input value, so I tried calling in the function. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.