This seems chaotic and I long for a more organized solution.
I have different HTML elements:
<input class="form-control" required="true" name="Spanish" type="text" value="blah blah" id="lang_1">
<input class="form-control" required="true" name="French" type="text" value="hey hey hey" id="lang_2">
To save them, I use this method:
function saveTranslations() {
var htmlRows = $("[id^=lang]");
var rowCount = htmlRows.size();
for (i = 0; i < rowCount; i++) {
ARRAY_LANGUAGE_ID[i] = htmlRows[i].id;
ARRAY_DESCRIPTION[i] = htmlRows[i].value;
}
}
Next, I utilize AJAX:
$.ajax({
type: 'PATCH',
url: 'products/' + id,
data: {
languageIDs: ARRAY_LANGUAGE_ID,
descriptiond: ARRAY_DESCRIPTION
}
});
This approach doesn't feel quite right. Is there a better way to accomplish this task?
Mick
Here is a slightly improved version:
var translations = $("[id^=lang]").serializeArray()