Note that there are some explanatory texts on larger screens.

plurals
  1. POmy javascript freeze the screen and there is no mistake, just the navigator does not work
    primarykey
    data
    text
    <p>I met a trouble with a script I have done, this script should allocate an amount to diferent fields.</p> <p>In fact here is the script, I will give you after the jsfiddle.</p> <pre><code> &lt;script type="text/javascript"&gt; function getItems() { var items = new Array(); var itemCount = document.getElementsByClassName("items"); for(var i = 0; i &lt; itemCount.length; i++) { items[i] = document.getElementById("p"+(i+1)).value; } return items; } function setItems(items,payAmt) { //document.getElementById("troppercu").value = payAmt; for(var i = 0; i &lt; items.length; i++) { document.getElementById("p" + (i+1)).value = items[i]; } } function itemSum(items) { var sum = 0; for(var i=0; i &lt; items.length; i++) { sum = items[i] + sum; } return sum; } function payment(inputElm) { var items = getItems(); var payAmt = document.getElementById("montantacompte").value; var i = 0; var sum = itemSum(items); while(payAmt != 0 &amp;&amp; sum != 0) { var temp = items[i] - payAmt; if(temp &gt; 0) { items[i] = Math.round((temp)*100)/100; break; } else if(temp &lt; 0) { items[i] = 0; payAmt = temp*-1; } i++; sum = itemSum(items); } setItems(items, payAmt); } &lt;/script&gt; </code></pre> <p>So I have an input in which I can write an amount, this amount will be allocate on the differents fields. </p> <p>Actualy, the trouble is that when I put an amount that is the same as the principal amount, it freeze the screen. If I write the same amount + 1 cent, it does not freeze, .</p> <p>All informations on the fields come from my databse. that is wrote with php and mysql.</p> <p><a href="http://jsfiddle.net/ywAU3/" rel="nofollow">http://jsfiddle.net/ywAU3/</a></p> <p>The trouble comes when you write the same amount as in the principal so for that case it will freeze the screen if you write on the yellow box input 3654.58 I really do not understand why, in fact it should not, because if I wite 3654.59 all works, If I write more, it works also.</p> <p>Receive all my utmost Respect.</p> <p>Kind Regards.</p> <p>SP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload