Hello.

It is necessary to check on the form whether the user has changed the form element type Select.

How to do it?

ps tried so

<select NAME="TEXT_FREQUENCY_TYPE_${row.ID}"> <option SELECTED VALUE="${row.FREQUENCY_TYPE}">${row.FREQUENCY_TYPE}</option> </select> 

 <script> function GetValue () { var result = []; [].forEach.call(document.querySelector('form').elements, function (el) { if (['checkbox', 'radio', 'button', 'submit'].indexOf(el.type) === -1 || el.checked) { var defValue = el.defaultValue; var currvalue = el.value; if (defValue == currvalue) { result.push(el.name + ' :: ' + el.value+' :: '+" Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π½Π΅ измСнилось"); } else { result.push(el.name + ' :: ' + el.value+' :: '+" Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ измСнилось с " + defValue + "\n Π½Π° " + currvalue); } </script> 

result:

 TEXT_FREQUENCY_TYPE_1 :: Minutes :: The value has changed from undefined to Minutes
  • And why do so? - HELO WORD
  • el.defaultValue does not exist, where did you get it from? - Jean-Claude
  • Whether the user changed the value of a select form element to something else other than the original value, for further processing of the result in the servlet - Nikolay Baranenko

1 answer 1

SELECT has a change event - it occurs when the value changes.

 // ΠŸΠ΅Ρ€Π΅Π±ΠΈΡ€Π°Π΅ΠΌ всС Ρ„ΠΎΡ€ΠΌΡ‹ Array.from(document.querySelectorAll('form')).forEach(form => { // ΠŸΠ΅Ρ€Π΅Π±ΠΈΡ€Π°Π΅ΠΌ всС SELECT Array.from(form.querySelectorAll('select')).forEach(select => { // И вСшаСм Π½Π° ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ SELECT ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ события change select.addEventListener('change', changeHandler); }); }); function changeHandler(){ // Π˜Ρ‰Π΅ΠΌ Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΡƒΡŽ Ρ„ΠΎΡ€ΠΌΡƒ, Π² Π½Π΅ΠΉ DIV ΠΈ ΠΏΠΎΠΌΠ΅Ρ‰Π°Π΅ΠΌ Π² Π½Π΅Π³ΠΎ сообщСниС this.closest('form').querySelector('div').innerHTML = 'SELECT Π² этой Ρ„ΠΎΡ€ΠΌΠ΅ ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½!'; } 
 form div{ color: red; } 
 <form> <input type='text' /> <select> <option value='one'>1</option> <option value='two'>2</option> </select> <div></div> </form> <hr /> <form> <input type='text' /> <select> <option value='one'>1</option> <option value='two'>2</option> </select> <div></div> </form> <hr /> <form> <input type='text' /> <select> <option value='one'>1</option> <option value='two'>2</option> </select> <div></div> </form>