On the form there are many elements that are formed in a dynamic way.

<table class="table"> <c:forEach var="row" items="${rs0.rows}"> <c:set var="SIGNIFICATIVE" value="${row.SIGNIFICATIVE}"/> <c:set var="ID_SIGNIFICATIVE" value="${row.ID_SIGNIFICATIVE}"/> <tr> <td> <input type="checkbox" id="${ID_SIGNIFICATIVE}" NAME="CHECKBOX_${ID_SIGNIFICATIVE}"></td> <td style="width:50%">${SIGNIFICATIVE}</td> <td><div class="input-group"><input type="text" class="form-control" id="${ID_SIGNIFICATIVE}" NAME="TEXT_${ID_SIGNIFICATIVE}" > <span class="input-group-addon">,%</span> </div></td> </tr> </c:forEach> </table> 

Further information from these form elements must be entered into the database. Tell me the method by which it is possible to get a list of modified form elements.

  • Depends on where exactly the changes need to be checked. If on the client - post events on onChange. If on the server - request the original from the database and compare. - Zelta

1 answer 1

it turned out to be done this way, the state of all the objects of the form is requested here, plus the form objects of the type ['checkbox', 'radio', 'button', 'submit'] are filtered out and only those for which there was a change are added to vars_for_update

 <SCRIPT language="javascript"> function GetValue () { var result = []; var vars_for_update=""; [].forEach.call(document.querySelector('form').elements, function (el) { if (['checkbox', 'radio', 'button', 'submit'].indexOf(el.type) === -1 ) // || el.checked { //var elem = el.name; var defValue = el.defaultValue; var currvalue = el.value; var index = el.selectedIndex; if (index) defValue = el.options[0].value; if (defValue == currvalue || index === 0) { result.push(el.name + ' :: ' + el.value+' :: '+" Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π½Π΅ измСнилось"); } else { result.push(el.name + ' :: ' + el.value+' :: '+" Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ измСнилось с " + defValue + "\n Π½Π° " + currvalue); vars_for_update=vars_for_update+el.name + '==' + el.value+"<>;"; } } }); demo.innerHTML = result.join('<br>'); if (vars_for_update!="") { document.getElementById("Text_Update").value=vars_for_update; } } </SCRIPT>