Hi
I have below code & i want when user Clicks on Edit then in Modal Update & Cancel should get displayed.
Modal Title should get changed to Update
- class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">class="modal-dialog">class="modal-content">class="modal-header">
class
="modal-title">Add New Location- class="close" data-dismiss="modal" aria-hidden="true">×
class="modal-body">class="form-horizontal">class="form-group">- ="Name">Location Id
- "text" class="form-control" id="txtId" placeholder="Location Id" />
class="form-group">- ="Name">Location Name
- "text" class="form-control" id="txtDescription" placeholder="Location Name" />
class="modal-footer">- class="btn btn-outline-dark" data-dismiss="modal">Cancel
- class="btn btn-primary" id="btnAdd" onclick="return Add();">class="glyphicon glyphicon-ok">Save Changes
- class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update
- $(document).ready(function () {
- $("#tblLocation").dataTable({
- ajax: {
- type: "get",
- url: "/Location/List",
- dataType: "json",
- dataSrc: ""
- },
- paging: true,
- sort: true,
- pageLength: 5,
- searching: true,
- columns: [
- { 'data': 'Id' },
- { 'data': 'Description' },
- {
- //"data": null,
- "defaultContent": ''
- }
- ]
- });
- $('body').on('click', '[id*=btnEdit]', function () {
- var data = $(this).parents('tr').find('td');
- var id = data.eq(0).html();
- var description = data.eq(1).html();
- $('[id*=txtId]').val(id);
- $('[id*=txtDescription]').val(description);
- $('#myModal').modal("show");
- });
- });
- function Update() {
- var res = validate();
- if (res == false) {
- return false;
- }
- var objLocation = {
- Id: $('#txtId').val().toUpperCase(),
- Description: $('#txtDescription').val().toUpperCase()
- };
- $.ajax({
- url: "/Location/Update",
- data: JSON.stringify(objLocation),
- type: "POST",
- contentType: "application/json;charset=utf-8",
- dataType: "json",
- success: function (result) {
- $('#tblLocation').DataTable().ajax.reload();
- $('#myModal').modal('hide');
- clearTextBox();
- },
- error: function (errormessage) {
- alert(errormessage.responseText);
- }
- });
- }
Thanks
Sachin SinghPosted May 29, 2021, 6:25 AM