How to add inputs values generated with a loop using jQuery in PHP -


how can values of inputs generated jquery loop in php?

i have 2 inputs, generated loop , need 2 inputs jquery use validation in our thesis.

the code is:

<?php ($i=0; $i <5 ; $i++) {     echo "$i.            <input class='text$i' type='text' name='text$i'>         <input class='text$i' type='text' name='text$i'>         </br></br>";              ?>     <script type="text/javascript" src="jquery.js"></script>     <script type="text/javascript">         $(document).ready(function(){             $(<?php echo "'.text$i"?> ).each(function(){                 $(this).keyup(function(){                     calculatesum();                 });             });         });          function calculatesum() {             var sum = 0;             $(<?php echo "'.text$i'";?>).each(function()              {                 if(!isnan(this.value) && this.value.length!=0)                 {                     sum += parsefloat(this.value);                 }                  $('#sum').html(sum.tofixed());             });         }     </script>      <?php     echo"<label>total:&nbsp;</label><span id='sum'>0</span>";     echo "</br>"; } ?> 

var calculatesum = function () {     var sum = 0;     $('.class1').each(function () {         if (!isnan(this.value) && this.value.length !== 0) {             sum += parsefloat(this.value);         }          $('#sum').html(sum.tofixed());     }); };   $('.class1').each(function () {     $(this).keyup(function () {         calculatesum();      }); }); 

working demo


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -