Pick button id clicked when you click another button

0

I need to make when the user clicks the radio button, it saves that value of the id and when clicking on another button "confirm" it shows the id of the first button clicked.

I tried to do with localstorage, but it ends up showing all the id's of all the buttons.

        <div class="row">
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="1">EXCEDEU O HORARIO</button>
      </div>
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="2">CLIENTE REALIZOU</button>
      </div>
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="3">ERRO DE ENTREGA</button>
      </div>
    </div>

<button type="button" class="btn btn-success but_pag_nao" id="confirm_ob" onClick="ok();">CONFIRMAR</button>
    
asked by anonymous 19.07.2018 / 17:07

2 answers

0

Solution using just javascript

window.idBotaoClicado =0;

function botaoClicado(e){
  window.idBotaoClicado= e
 }

function ok(){
  alert(window.idBotaoClicado)
 }
<div class="row">
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="1" onclick="botaoClicado(this.id)">EXCEDEU O HORARIO</button>
      </div>
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="2" onclick="botaoClicado(this.id)">CLIENTE REALIZOU</button>
      </div>
      <div class="col-sm">
        <button type="button" class="btn btn-primary" id="3" onclick="botaoClicado(this.id)">ERRO DE ENTREGA</button>
      </div>
    </div>

<button type="button" class="btn btn-success but_pag_nao" id="confirm_ob" onClick="ok();">CONFIRMAR</button>
    
19.07.2018 / 17:39
0

I think it would be easier if you showed what you're using, whether it's JQuery, or things like ... Well using pure JS we can do this:

var primeiroBtn = "";

function ok(elemento){
  primeiroBtn = elemento.id;
}

function cancel(){
  window.alert(primeiroBtn);
}
<button onClick="ok(this);" id="testeBTN">OK btn</button>
<button onClick="cancel();">Cancel bnt</button>
    
19.07.2018 / 17:51