Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Input Mask Not Working
    primarykey
    data
    text
    <p>I am trying to set up a donations page for people to give money to a non-profit and allow them to specify the uses of the money. I have it set up that it totals the amounts the giver puts in each field as they enter amounts. I am trying to add an input mask in each field, but it is just making my JavaScript crash and not do anything. Here is the code I currently have that works perfectly before any masks:</p> <pre><code>&lt;script src="/js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready( function() { var calcTot = function() { var sum = 0; $('.toTotal').each( function(){ sum += Number( $(this).val() ); }); $('#giveTotal').val( '$' + sum.toFixed(2) ); } calcTot(); $('.toTotal').change( function(){ calcTot(); }); }); &lt;/script&gt; </code></pre> <p>'toTotal' is the class name given to all the input boxes that need to be added up; that is also the class that needs a mask. 'giveTotal' is the id of the total field.</p> <p>I have tried several variations I have found on StackOverflow and other sites.</p> <p>Full Code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="/js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready( function() { //This is one of the masking codes I attempted. $('.toTotal').mask('9.99', {reverse: true}); //other options I have tried: //$('.toTotal').mask('9.99'); //$('.toTotal').mask('0.00'); //$('.toTotal').inputmask('9.99'); //$('.toTotal').inputmask('mask', {'mask': '9.99'}); var calcTot = function() { var sum = 0; $('.toTotal').each( function(){ sum += Number( $(this).val() ); }); $('#giveTotal').val( '$' + sum.toFixed(2) ); } calcTot(); $('.toTotal').change( function(){ calcTot(); }); //I have tried putting it here, too }); &lt;/script&gt; &lt;title&gt;Addition&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="text" class="toTotal"&gt;&lt;br /&gt; &lt;input type="text" class="toTotal"&gt;&lt;br /&gt; &lt;input type="text" class="toTotal"&gt;&lt;br /&gt; &lt;input type="text" id="giveTotal"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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.
 

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