Jump to content

Edit History

Adam

Adam

Hi

I have a script that will ultimately be used to extend the functionality of one of the modules.

It is used to count the values of all inputs and then, if too large a number is entered, correct the value on the front.

Here's what it looks like.

<input min="0" name="cat1" step="1" type="number" max="50" value="0" />

<input min="0" name="cat2" step="1" type="number" max="50" value="0" />

<input min="0" name="cat3" step="1" type="number" max="50" value="0" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
<script type="text/javascript">
        var max = 50;
var $inputs = $('input');


function sumInputs($inputs) {
  var sum = 0;
 
  $inputs.each(function() {
    sum += parseInt($(this).val(), 0);
  });

  return sum;
}


$inputs.on('input', function(e) {
  var $this = $(this);
  var sum = sumInputs($inputs.not(function(i, el) {
    return el === e.target;
  }));
  var value = parseInt($this.val(), 10) || 0;
  if(sum + value > max) $this.val(max - sum);
});

</script>


It works fine in html, but not in the store.

To make things easier, I added the code to one of the tpl files to make it easier - removing the original content first.

The browser shows it as in HTML - the function refers to the inputs, but in the front-end store it does not correct the values (screens).


Request for help.
Thanks in advance.

obraz.png

obraz.png

Adam

Adam

Hi

I have a script that will ultimately be used to extend the functionality of one of the modules.

It is used to count the values of all inputs and then, if too large a number is entered, correct the value on the front.

Here's what it looks like.

<input min="0" name="cat1" step="1" type="number" max="50" value="0" />

<input min="0" name="cat2" step="1" type="number" max="50" value="0" />

<input min="0" name="cat3" step="1" type="number" max="50" value="0" />


It works fine in html, but not in the store.

To make things easier, I added the code to one of the tpl files to make it easier - removing the original content first.

The browser shows it as in HTML - the function refers to the inputs, but in the front-end store it does not correct the values (screens).


Request for help.
Thanks in advance.

obraz.png

obraz.png

Adam

Adam

Hi

I have a script that will ultimately be used to extend the functionality of one of the modules.

It is used to count the values of all inputs and then, if too large a number is entered, correct the value on the front.

Here's what it looks like.

 


It works fine in html, but not in the store.

To make things easier, I added the code to one of the tpl files to make it easier - removing the original content first.

The browser shows it as in HTML - the function refers to the inputs, but in the front-end store it does not correct the values (screens).


Request for help.
Thanks in advance.

obraz.png

obraz.png

×
×
  • Create New...