Get JSP foreach value in Jquery to display in label

Asked

Viewed 203 times

1

I would like help to catch a figure that is set within a forEach in my JSP, play for Jquery and it display in a label on the same page.

That one forEach retrieves a direct list from the database. I used a hidden to redeem the amount I need, the: lista.deTipo. It turns out that this loop runs twice in the bank, but when I take that amount by the id of hidden it only returns the first value of deTIpo. The rest it does not catch and I do not know how to go through this loop on the Jquery side to take these two values to lista.deTipo.

Follow the jsp code registrar.jsp:

<html:radio name="formulRadio" property="nuTipo" styleId="radioTipo" value="1"/>&nbsp;Tipo Interno&nbsp;&nbsp;&nbsp;&nbsp;
            <html:radio name="formulRadio" property="nuTipo" styleId="radioTipo" value="2"/>&nbsp;Tipo Externa&nbsp;&nbsp;&nbsp;&nbsp;
<c:forEach var="lista" items="${form.listaPo}" varStatus="listaMotivo" >
                    <input type="hidden" name="deTipo" id="deTipo" value="${lista.deTipo}">
                </c:forEach>

No js registra.js

$('#form input:radio').bind("click", function() {

    if ($(this).is(':checked')) {
        var tipo = $("input[@name='formulRadio']:checked").value;
        tipo = parseInt($(this).val());

        if(tipo == "2"){
            mensagemAlerta("Radio tipo externo acionado."+tipo,"INF");
                var deTipo = $("#deTipo").val();
                document.getElementById("descMotivo").innerHTML = deTipo;
    }
        else if(tipoTce =="1"){

            var deTipo = $("#deTipo").val();
            mensagemAlerta("Radio externa acionado."+deTipo,"INF");         
                document.getElementById("descMotivo").innerHTML = deTipo;   
        }
}});
  • Why are you using jstl + jquery? You are checking an input:radio and not jstl radio. Use the Jquery radio (https://api.jquery.com/radio-selector/) to avoid mixing the components. I believe that it should only work by making this exchange.

  • Thank you, I’ll change! This project already exists and I’m a beginner. So I’m having a lot of questions.

No answers

Browser other questions tagged

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