Capture Hidden value in lopping

Asked

Viewed 227 times

1

I would like help on how to get a value of one hidden that is in a useful. I need that value to send to the next screen, but since it’s on a multi-line table, I’m not getting it done. I need to get this value in javascript.

The screen:

<div class="grupoLista">
   <util:tabela id="lista" colecao="${form.listaPrograma12}" paginar="true" indiceProperty="lerDe" totalRegistrosProperty="qtdTotalLista" tamanhoPagina="30" idxLinha="true">
   <util:coluna id="id" titulo="" propriedade="nuContrato" tipo="radio">
      <input type="radio"     name="listaIndice"          value="${idxLinha}" />
      <input type="hidden"    name="listanuContrato"      value="${lista.nuContrato}" />
      <input type="hidden"    name="listanuStatus"        value="${lista.nuStatus}" />
      <input type="hidden"    name="listanoStatus"        value="${lista.noStatus}"/>
      <input type="hidden"    name="listanoEmpresa"       value="${lista.noEmpresa}"/>
      <input type="hidden"    name="listanoGestor"        value="${lista.noGestor}"/>
      <input type="hidden"    name="listadtAssina"        value="${lista.dtAssina}"/>
      <input type="hidden"    name="listavlContrato"      value="${lista.vlContrato}"/>
      <input type="hidden"    name="listavlDevolucao"     value="${lista.vlDevolucao}"/>
      <input type="hidden"    name="listavlDev"   value="${lista.vlDev}"/>
      <input type="hidden"    name="listanuEstagio"       value="${lista.nuEstagio}"/>
      <input type="hidden"    name="listanoEstagioCont"   value="${lista.noEstagio}"/>
   </util:coluna>
</div>

The js

function listar(){
    var validado = true;
    if(!checkRadio()){
        mensagemAlerta("Selecione uma das opções na lista.", "INF");
        validado = false;
    }
    if(validado){
        var linSel = $("input[name=listaIndice]:checked").val();
        document.getElementById("nuContrato").value = $("#listanuContrato" + linSel).val();
        document.getElementById("nuStatus").value = $("#listanuStatus" + linSel).val();

        var idEstagio = $("input[name=listanuEstagio]" + linSel).val();
        document.getElementById("selEstagioCont").value = idEstagio;

        var noEstagio = $("input[name=listanoEstagioCont]").val();
        document.getElementById("noSelEstagioCont").value = noEstagio;


        submitForm("listarContratoDevolucao");
    }

}

In short: In jsp a list is mounted, a table with several rows and columns as well. I select a line through a radio and press the button to send what I have selected. I need to take the Field Liststagio of what was selected and play in another Hidden, so when you press the send button, this value remains for the next screen. The situation is: how to capture this listStationio since it is part of a mounted list, with the code I made it is only returning the value of the first line.

*in time: I am only doing code maintenance.

Follows HTML code:

<html><head></head><body><div id="modalPane" style="visibility: hidden;"></div><div id="container"><div id="header"></div><div id="corpo"><div class="confidencialidade"></div>
      <!-- corpo -->
    <div id="funcao"></div><div class="divisor"></div><div style="float:left;float:right;"></div>
<form id="form" action="/projet/programa.do" method="post" name="ContratoForm">
<input id="breadCrumb" type="hidden" value="/projeto/programa.do?.....?mt=pesquisar;" name="breadCrumb">
</input><input id="backPage" type="hidden" value="/projeto/programa.do?mt=ini" name="backPage"></input>
<input id="mt" type="hidden" value="pesquisar" name="mt">
</input><input id="nuContrato" type="hidden" value="9999999" name="nuContrato"></input><input id="chkFiltroNumCont" type="hidden" value="" name="chkFiltroNumContr"></input>
<input id="tela" type="hidden" value="lista" name="tela"></input><div id="conteudo"><div class="informacao">
      CNPJ:  
    <b></b></div><div class="informacao">
      Nome Contratante:  
    <b></b></div><div class="grupoLista"><script type="text/javascript"></script><input id="qtdTotalLista" type="hidden" value="31" name="qtdTotalLista"></input><div id="divIE" class="divlinhaTabela"><table id="tblIE" class="dados" width="100%">
<tbody>
<tr class="azul">
<th></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap"></th><th nowrap="nowrap" style="text-align:right"></th><th nowrap="nowrap" style="text-align:right"></th><th nowrap="nowrap" style="text-align:right"></th></tr>
<tr class="branco">
<td><input type="radio" value="0" name="listaIndice"></input>
<input type="hidden" value="9999999" name="listanuOperacao"></input>
<input type="hidden" value="4" name="listanuSituacao"></input>
<input type="hidden" value="Contratada/Notificado" name="listanoSituacao"></input>
<input type="hidden" value="Contrantante" name="listanoContratado"></input>
<input type="hidden" value="Gestor" name="listanoGestor"></input>
<input type="hidden" value="19/02/2016" name="listadtAssina"></input>
<input type="hidden" value="0000000000010000.00" name="listaValor></input>
<input type="hidden" value="0000000000000000.00" name="listavlDev"></input>
<input type="hidden" value="0000000000000000.00" name="listavlCredito"></input>
<input type="hidden" value="4" name="listanuEstagio'0'"></input>
<input type="hidden" value="Notificado de TCE" name="listanoEstagioOper"></input></td>
<td nowrap="nowrap"></td>
<td nowrap="nowrap"></td>
<td nowrap="nowrap">

                    9999999 - 99

</td><td nowrap="nowrap">
      Contratada/Notificado
</td><td nowrap="nowrap"></td>
<td nowrap="nowrap"></td>
<td nowrap="nowrap">
      Contratante
    </td><td nowrap="nowrap"></td>
<td nowrap="nowrap"></td>
<td nowrap="nowrap" style="text-align:right"></td>
<td nowrap="nowrap" style="text-align:right"></td>
<td nowrap="nowrap" style="text-align:right"></td>
</tbody>
</table>
</div><div class="paginacao"><div class="numeros"></div>
<div style="float:left;"></div></div>
<span class="total"></span>
<div class="grupoBotaoLista"><div class="divisor"></div>
<img class="botao" onclick="listar();" src="resources/_images/botoes/bt_listar.gif" alt=""></img>
<img class="botao" onclick="volta();" src="resources/_images/botoes/bt_voltar.gif" alt=""></img></div></div></div>
</form>
      <!-- mensagem -->
    </div><div id="rodape"></div></div><form id="idsp" method="post" action="#"></form></body></html>
  • These inputs and radio are inside the same <TD> cell or in the same <TH> row>?

  • They’re on the same line, I didn’t post all the code, but this radio stays in one column and ss repeats in several lines.

  • I have tried: Document.getElementById(""). value = $("#listingEstagio" + linSel). val(); but it does not feed selEstagioCont, and when asked to display gives unidefined

  • Try to get the value from this: var idEstagio = $("input[value="+linSel+"]").closest("td").find("input[name=listanuEstagio]").val();... if it doesn’t work, change the "td"for "th" or "tr".

  • I’ll try okay. Thank you

  • made the change, but when executing on the page, appeared the message: [13:08:05.499] Typeerror: $(...). Closest is not a Function

  • Your code has many errors, for example, this value without closing the quotes: name="listaValor and that value here: name="listanuEstagio'0'"... that '0' inside the name that is correct?

  • This was an attempt to concatenate a value for me to recognize the number of the stage (unsuccessful attempt). The original code looked like this : <input type="Hidden" value="4" name="listanuEstagio"></input>

Show 3 more comments

2 answers

1

Adds class to inputs:

  <input type="radio" class="listaIndice"    name="listaIndice"          value="${idxLinha}" />
  <input type="hidden" class="listanuContrato"   name="listanuContrato"      value="${lista.nuContrato}" />
  <input type="hidden" class="listanuStatus"   name="listanuStatus"        value="${lista.nuStatus}" />
  <input type="hidden" class="listanoStatus"   name="listanoStatus"        value="${lista.noStatus}"/>
  <input type="hidden" class="listanoEmpresa"   name="listanoEmpresa"       value="${lista.noEmpresa}"/>
  <input type="hidden" class="listanoGestor"   name="listanoGestor"        value="${lista.noGestor}"/>
  <input type="hidden" class="listadtAssina"   name="listadtAssina"        value="${lista.dtAssina}"/>
  <input type="hidden" class="listavlContrato"   name="listavlContrato"      value="${lista.vlContrato}"/>
  <input type="hidden" class="listavlDevolucao"   name="listavlDevolucao"     value="${lista.vlDevolucao}"/>
  <input type="hidden" class="listavlDev"   name="listavlDev"   value="${lista.vlDev}"/>
  <input type="hidden" class="listanuEstagio"   name="listanuEstagio"       value="${lista.nuEstagio}"/>
  <input type="hidden" class="listanoEstagioCont"   name="listanoEstagioCont"   value="${lista.noEstagio}"/>

in javascript:

function listar(){
var validado = true;
if(!checkRadio()){
    mensagemAlerta("Selecione uma das opções na lista.", "INF");
    validado = false;
}
if(validado){
    var linSel = $("input[name=listaIndice]:checked").closest("tr");

    document.getElementById("nuContrato").value = linSel.find('.listanuContrato').val();

    // restantes vars

    submitForm("listarContratoDevolucao");
}
}

1


To take the values of each input hidden informed in question, you can use the following code in your function:

// esta linha já possui no seu código. OK!
var linSel = $("input[name=listaIndice]:checked").val();

// nesta linha eu seleciono a célula TD onde estão todos os inputs
// e atribuo a uma variável "elementos"
var elementos = $("input[value="+linSel+"][type=radio]").closest("td");

// nesta linha eu uso a variável "elementos" para pegar os valores
// dos inputs pelo nome. Para pegar os valores que quiser, basta
// criar uma nova linha igual e substituir o name= pelo nome do input
// que quer pegar
var idEstagio = elementos.find("input[name=listanuEstagio]").val();

As your code has many errors, this example below will serve to show how it works. Run, check the radio and click on List to see the value of the field listanuEstagio:

function listar(){
   var validado = true;
//   if(!checkRadio()){
//      mensagemAlerta("Selecione uma das opções na lista.", "INF");
//      validado = false;
//   }
   if(validado){
var linSel = $("input[name=listaIndice]:checked").val();
var elementos = $("input[value="+linSel+"][type=radio]").closest("td");
var idEstagio = elementos.find("input[name=listanuEstagio]").val();

//        document.getElementById("selEstagioCont").value = idEstagio;

//        var noEstagio = $("input[name=listanoEstagioCont]").val();
//        document.getElementById("noSelEstagioCont").value = noEstagio;

      alert(idEstagio);
//        submitForm("listarContratoDevolucao");
   }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="modalPane" style="visibility: hidden;"></div>
<div id="container">
   <div id="header"></div>
   <div id="corpo">
      <div class="confidencialidade"></div>

      <!-- corpo -->

      <div id="funcao"></div>
      <div class="divisor"></div>
      <div style="float:left;float:right;"></div>

      <form id="form" action="/projet/programa.do" method="post" name="ContratoForm">

         <input id="breadCrumb" type="hidden" value="/projeto/programa.do?.....?mt=pesquisar;" name="breadCrumb">
         <input id="backPage" type="hidden" value="/projeto/programa.do?mt=ini" name="backPage">
         <input id="mt" type="hidden" value="pesquisar" name="mt">
         <input id="nuContrato" type="hidden" value="9999999" name="nuContrato"><input id="chkFiltroNumCont" type="hidden" value="" name="chkFiltroNumContr">
         <input id="tela" type="hidden" value="lista" name="tela"><div id="conteudo"><div class="informacao">

         CNPJ:  

         <b></b>
   </div>
   <div class="informacao">

      Nome Contratante:  

      <b></b>
   </div>
   <div class="grupoLista">
      <script type="text/javascript"></script>
      <input id="qtdTotalLista" type="hidden" value="31" name="qtdTotalLista">
      <div id="divIE" class="divlinhaTabela">
         <table id="tblIE" class="dados" width="100%">
            <tbody style="border: 1px solid #000;">
               <tr class="azul">
                  <th></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap"></th>
                  <th nowrap="nowrap" style="text-align:right"></th>
                  <th nowrap="nowrap" style="text-align:right"></th>
                  <th nowrap="nowrap" style="text-align:right"></th>
               </tr>
               <tr class="branco">
                  <td>
                     <input type="radio" value="0" name="listaIndice">
                     <input type="hidden" value="9999999" name="listanuOperacao">
                     <input type="hidden" value="4" name="listanuSituacao">
                     <input type="hidden" value="Contratada/Notificado" name="listanoSituacao">
                     <input type="hidden" value="Contrantante" name="listanoContratado">
                     <input type="hidden" value="Gestor" name="listanoGestor">
                     <input type="hidden" value="19/02/2016" name="listadtAssina">
                     <input type="hidden" value="0000000000010000.00" name="listaValor">
                     <input type="hidden" value="0000000000000000.00" name="listavlDev">
                     <input type="hidden" value="0000000000000000.00" name="listavlCredito">
                     <input type="hidden" value="4" name="listanuEstagio" />
                     <input type="hidden" value="Notificado de TCE" name="listanoEstagioOper"></td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap">
                     9999999 - 99
                  </td>
                  <td nowrap="nowrap">
                     Contratada/Notificado
                  </td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap">
                     Contratante
                  </td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap"></td>
                  <td nowrap="nowrap" style="text-align:right"></td>
                  <td nowrap="nowrap" style="text-align:right"></td>
                  <td nowrap="nowrap" style="text-align:right"></td>
            </tbody>
         </table>
      </div>
      <div class="paginacao">
         <div class="numeros"></div>
         <div style="float:left;"></div>
      </div>
      <span class="total"></span>
      <div class="grupoBotaoLista">
         <div class="divisor"></div>

            <img class="botao" onclick="listar();" src="resources/_images/botoes/bt_listar.gif" alt="">
            <img class="botao" onclick="volta();" src="resources/_images/botoes/bt_voltar.gif" alt="">
         </div>
      </div><br />
   </div>
</form>

<!-- mensagem -->
</div>
<div id="rodape"></div></div>
<form id="idsp" method="post" action="#"></form>
<input type="button" value="listar" onclick="listar()" />

  • Thanks for the help, I also managed with the command : Document.getElementById("nuEstagio"). value = Document.getElementsByName("listanuEstagio")[linSel]. value;

Browser other questions tagged

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