0

I have a loop in the html document that makes the input for me,

foreach (var prosize in productsize)
    {
        <span class="stylesize js-size">@prosize</span>
        <input type="checkbox" class="js-choosesize" value="@prosize" />

    }

Jquery :

 const sizes = [];
            Pform.find('.js-choosesize:checked').each(function (i) {
                sizes[i] = $(this).val();
            });

in browser :

    <span class="stylesize js-size">36</span>
    <input type="checkbox" class="js-choosesize" value="36">
    <span class="stylesize js-size">37</span>
    <input type="checkbox" class="js-choosesize" value="37">
    <span class="stylesize js-size">38</span>
    <input type="checkbox" class="js-choosesize" value="38">

First: I want the number of inputs to be controlled, that is, if the user increases or decreases the element with "Inspect-Element", This will be controlled?

Second: If the user changes the values ​​with the "Inspect-Element" or enters a duplicate value, the duplicate values ​​will be recorded in the object only once.

sunboy_sunboy
  • 225
  • 2
  • 14
  • what is "Inspect-Element"? What does "controlled" mean? – Tomalak Feb 14 '22 at 09:17
  • @Tomalak Control `sizes[]`values – sunboy_sunboy Feb 14 '22 at 09:22
  • You need to reconsider your security requirements. Anything the browser can do, a user an do manually, eg `$(".js-choosesize").first().val("31")` - there are ways to "watch" DOM changes, but they're not security. eg `function checkForChanges() { ... your code to check for changes ... }` can quickly become: `function checkForChanges() { return false; }` via the console. – freedomn-m Feb 14 '22 at 09:27
  • @freedomn-m Can you give an example with the code? – sunboy_sunboy Feb 14 '22 at 10:34
  • https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener – freedomn-m Feb 14 '22 at 10:36

1 Answers1

0

I Used This Code

 Frm_AddProduct.on('DOMSubtreeModified', function () {
            location.reload();
            console.log('changed');
        });

This is a good solution, but in terms of security, I do not know if it is good or not

sunboy_sunboy
  • 225
  • 2
  • 14