1

This page displays several records when i select the Crime Number form the href tag i only want to post the data in that row only. Can someone tell me where i am going wrong here: I did a different form for each record that returns from the server but only the first record gets returned all the time.

EDIT The page is POST using java script and the Id its receiving is NULL

The crimeRecNo is posted accurately however the victim and criminal list only the first row is posted and not the selected one.Why????

function submitPage(crimeRecNo) {

        document.getElementById("crimeList"+$('#crimeRecNo').val()).action = "getCrime/"+ crimeRecNo + ".htm";
        document.getElementById("crimeList"+$('#crimeRecNo').val()).method = "POST";
        document.getElementById("crimeList"+$('#crimeRecNo').val()).submit();

    }

Html

  </head>
<body>
    <c:forEach items="${crimes}" var="crime">
        <form:form id="crimeList${crime.crimeRecNo}" name="crimeList" commandName="crime">
            <div id="content">

                <div class="row-${crime.crimeRecNo}">
                    <h2>                            
                        <a class="crimeRecNo" href="${crime.crimeRecNo}">Crime Record
                            Number : ${crime.crimeRecNo}</a><form:input path="crimeRecNo" id="crimeRecNo"
                                            value="${crime.crimeRecNo}" />

                    </h2>

                    <div class="crimeReport">
                        <label>${crime.crimeDetails}</label>
                    </div>

                    <div id="container">

                        <div id="crimePhotoz">
                            <div id="victimLabel">
                                <label class="heading">Victims/Witness In Crime</label>
                            </div>
                            <div class="grid_row">

                                <c:forEach items="${crime.victims}" var="victim">
                                    <input type="hidden" value="${victim.photo}" class="foto" />
                                    <canvas class="canvas" height="200" width="200"></canvas>
                                </c:forEach>

                                <c:forEach items="${crime.victims}" var="victim">
                                    <div class="names">
                                        <a class="crimeNames" href="${victim.socialSecurityNumber}">${victim.name}</a>
                                        <form:input path="victims" id="victims" value="${victim.socialSecurityNumber}" />
                                    </div>
                                </c:forEach>

                            </div>

                            <div id="criminalLabel">
                                <label class="heading">Criminals In Crime</label>
                            </div>
                            <div class="grid_row2">

                                <c:forEach items="${crime.criminals}" var="criminal">
                                    <input type="hidden" value="${criminal.photo}" class="foto" />
                                    <canvas class="canvas" height="200" width="200"></canvas>
                                </c:forEach>

                                <c:forEach items="${crime.criminals}" var="criminal">
                                    <div class="names">
                                        <a class="crimeNames" href="${criminal.socialSecurityNumber}">${criminal.name}</a>
                                        <form:input path="criminals" id="criminals" value="${criminal.socialSecurityNumber}" />
                                    </div>
                                </c:forEach>
                            </div>
                        </div>
                    </div>
                </div>
                <hr>
            </div>
        </form:form>
    </c:forEach>


</body>
</html>
devdar
  • 5,244
  • 23
  • 88
  • 152
  • could you provide some more details on what you want to achieve? maybe how you want the request url / params to be and how the controller method signature should be? Also where is crimeRecNoBinder defined? How is the binder added to the context? – Akshay Apr 20 '13 at 15:48

1 Answers1

2

Maybe you are missing some quotes?

document.getElementById(${crime.crimeRecNo})

If ${crime.crimeRecNo} is a string this becomes

document.getElementById(myRecNo)

which is invalid javascript. In this case you should add quotes:

document.getElementById("${crime.crimeRecNo}")

If ${crime.crimeRecNo} is a number you don't need quotes but then you might have invalid ids. According to this html ids must at least start with a character. Iam not sure if this can cause problems but maybe you should try <form id="record-${crime.crimeRecNo}" .. >

Community
  • 1
  • 1
micha
  • 42,796
  • 15
  • 68
  • 78
  • i tried this document.getElementById("crimeList"+ $('.crimeRecNo').val()).action = "getCrime/"+ crimeRecNo + ".htm"; and the values are not concatenating – devdar Apr 20 '13 at 19:21
  • 1
    Does `$('.crimeRecNo').val()` return the correct value? There are multiple elements with the class `.crimeRecNo`. – micha Apr 20 '13 at 19:27
  • ok yes i got that part to work now i use using class instead of id. However i am still getting values form the first record being returned for criminals and victims. Why?? – devdar Apr 20 '13 at 19:30
  • 1
    Does your javascript function gets called with the correct `crimeRecNo` parameter? – micha Apr 20 '13 at 19:32
  • yes i saw in firebug where the correct crimeRecNo is sent however in the NET i am seeing the correct crimeRecNo but the criminals and victims values are from the first row – devdar Apr 20 '13 at 19:34