How do i set values back into a map in jquery?
This is the code that of my jsp page which displays a window with columns.Each column corresponds to a form
<%@include file="/WEB-INF/jsp/include/pagedirectives.jsp"%>
<div style="background: #D6E8FF; padding: 10px;" class="advanced_search">
<%@include file="/WEB-INF/jsp/include/page.topmessagebox.jsp"%>
<table class="form" cellspacing="0" id="requestSubmissionEform">
<tbody>
<tr>
<td class="label"><b>Label</b></td>
<c:forEach var="i" begin="1" end="5" step="1" varStatus ="status">
<th id="form_${i}" class="label" align="left"><b>Form ${(pageNumber * 5) + i}</b></th>
</c:forEach>
</tr>
<c:forEach items="${eformDetailsList}" var="eformDetails"
varStatus="status">
<tr id="serviceTypeWithEform">
<td class="label">
<label for="${eformDetails.id}_0"><c:out value="${eformDetails.label}" /></label>
<input type="hidden" id="label_${eformDetails.id}_0" value="${eformDetails.label}" name="label_0"></input>
<input type="hidden" id="index_${eformDetails.id}_0" value="${eformDetails.id}" name="index_0"></input>
</td>
<c:if test="${eformDetails.controlType==1}">
<td id="Col0" style="visibility: visible;">
<input id="eformDetail_${eformDetails.id}_0" class="eformDetail" type="text" value="" name="form_0"></input>
</td>
<td id="Col1" style="visibility: visible;">
<input id="eformDetail_${eformDetails.id}_1" class="eformDetail" type="text" value="" name="form_1"></input>
</td>
<td id="Col2" style="visibility: visible;">
<input id="eformDetail_${efo开发者_开发知识库rmDetails.id}_2" class="eformDetail" type="text" value="" name="form_2"></input>
</td>
<td id="Col3" style="visibility: visible;">
<input id="eformDetail_${eformDetails.id}_3" class="eformDetail" type="text" value="" name="form_3"></input>
</td>
<td id="Col4" style="visibility: visible;">
<input id="eformDetail_${eformDetails.id}_4" class="eformDetail" type="text" value="" name="form_4"></input>
</td>
</c:if>
</tr>
</c:forEach>
<c:if test="${empty eformDetailsList}">
<tr id="serviceTypeWithNoEform">
<td><b>There is no eform associated with this Service Type</b></td>
</tr>
</c:if>
</tbody>
</table>
This is the jquery used to obtain the values from the jsp page :
var labels0=$('input[name="label_0"]').map(function(){
return $(this).val() }).get();
var index0=$('input[name="index_0"]').map(function(){
return $(this).val() }).get();
var fields0 = $('input[name="form_0"]').map(function(){
return $(this).val() }).get();
var fields1 = $('input[name="form_1"]').map(function(){
return $(this).val() }).get();
var fields2 = $('input[name="form_2"]').map(function(){
return $(this).val() }).get();
var fields3 = $('input[name="form_3"]').map(function(){
return $(this).val() }).get();
var fields4 = $('input[name="form_4"]').map(function(){
return $(this).val() }).get();
On click of save,I have saved the values.When i open the form again i want the saved values to re-appear in my text boxes.Is there a way to re set the values back to the map?
(I think you should do it with jsp..) Anyway, assuming you have the js array:
var label_0_values = ['value 1', 'value 2', ...];
With jQuery, you would populate like this:
$('input[name="label_0"]').each(function(i){
$(this).val(label_0_values[i]);
});
And the same for your other inputs
Hope this helps. Cheers
精彩评论