Is there a way to get the custom HTML data-*
attributes for the selected radio button when you submit a form? The value does not seem to get picked up by serializeArray()
.
HTML
<form id="preference-form">
<table>
<tr class ="result">
<td width="100%">{{Title}}</td>
<td><input type="radio" id="radio-{{Project_No}}-1" data-application="{{Application_ID}}" name="{{Project_ID}}" value="1"></td>
<td><input type="radio" id="radio-{{Project_No}}-2" data-application="{{Application_ID}}" name="{{Project_ID}}" value="2"></td>
<td><input type="radio" id="radio-{{Project_No}}-3" data-application="{{Application_ID}}" name="{{Project_ID}}" value="3"></td>
<td><input type="radio" id="radio-{{Project_No}}-9" data-application="{{Application_ID}}" name="{{Project_ID}}" value="9"></td>
</tr>
</table>
</form>
JavaScript
$("#preference-form).on('submit', function() {
var data = $(this).serializeArray();
console.log(data)
});
This outputs the name
and value
fields, but I can't seem to find a simple answer about the data-*
fields. Unfortunately, I need all three pieces of information in order to perform an update on the database record, and from what I understand:
- Each ID and Value field has to be unique,
- Each name field has to be identical to group the elements.
I think the tricky part for this is the multiple elements compared to a single element.