I want to get all values in ‘input’ and show them in the modal table using js. How can i do that?
My script:
<script>
$(document).ready(function() {
$(document).on('click', '.save', function() {
var id = $(this).val();
var name = $('#name' + id).val();
$('#edit').modal('show');
$('#sname').val(name);
});
});
</script>
My modal
<!-- The Modal -->
<div class="modal" id="edit">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4>If you are sure of the information you entered, press the "OK" button</h4>
</div>
<!-- Modal body -->
<div class="modal-body" >
<table class="table table-bordered">
<tbody>
<tr>
<th scope="row">Full name</th>
<td>
<input class="form-control" id="sname">
</td>
</tr>
</tbody>
</table>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="submit" name="action" class="btn btn-outline-primary" onclick="return validateForm();" value="Save" >OK</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Back</button>
</div>
</div>
</div>
</div>
</div>
Form to input data
<s:form name="myForm" action="saveProcess" items="${employeeList}" var="e" modelAttribute="employee" style="margin-top: 100px;" onsubmit="return validateForm()">
<div class="form-group">
<s:input type="hidden" path="id" class="form-control"placeholder="Enter Id" />
</div>
<div class="form-group">
<label>Full name</label>
<s:input path="fullname" type="text" id="name" placeholder="Enter Fullname" class="form-control" name="fullname" style="width: 500px; margin-top:-39px; margin-left: 150px"/>
</div>
<div class="container">
<button onclick="return validateForm();" type="button" class="btn btn-outline-primary save" style="position: relative; left: 200px; border-radius: 8px" >
Save
</button>
</div>
</s:form>
Now, when i entered data in input and clicked btn save, instead of using input, how can i use label, td,…????
>Solution :
Hard to parse your question exactly, but I think this is what you mean to do? just give a unique id or class to the td, then modify its contents using html().
javascript
$( '#label_td' ).html( name );
html
<tr>
<th scope="row">Full name</th>
<td id="label_td"></td>
</tr>