In rails5, I have the following in the index page:
<tbody>
<% @properties_payments.each do |properties_payment| %>
<tr>
<td><%= properties_payment.property_id %></td>
:
:
<td>
<a class="property-update" data-toggle="modal" data-
target="#property-modal" data-attr='<%= properties_payment.id %>'>Update
Payment Transcation</a>
</td>
</tr>
<% end %>
</tbody>
I have a modal header:
<div class="modal fade" id="property-modal" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Property Payment Update</h4>
</div>
<div class="modal-body" id="test"></div>
<div class="modal-footer">
<button type="submit" class="btn btn-default property-submit-status">Update</button>
</div>
</div>
</div>
</div>
Now using a script tag:
<script>
$(document).ready(function (e) {
$('.property-submit-status').on('click', function(e) {
var payment_id = $('#property-update').data('attr');
e.preventDefault();
e.stopPropagation();
var postdata = { payment_id:payment_id };
$.ajax({
type: 'post',
url: '/admin/properties/payments/update_transaction',
data: postdata,
}).done(function (data, textStatus, jqXHR) {
$('.result').html(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
setNotification('error', 'Unknown Error. Try Again');
});
})
});
</script>
I am not able to fetch the value of data-attr i.e properties_payment.id in var payment_id. How do I achieve this? Newbie to JavaScript.