ahaberman25 Posted December 1, 2012 Share Posted December 1, 2012 Ok so I did some homework and I figured out most of my previous issue, now I am down to a little problem that I am having issues with. I am using the code: <script type="text/javascript"> function updateTotal(){ var total = 0; for(var i=1; i<10; i++){ if(!isNaN(jQuery('#txt'+i).val())){ total = (parseInt(total) + parseInt(jQuery('#txt'+i).val())); } } jQuery('#total').html(total); if (total <= 6 ) { document.write("<p>Congratulations, you are getting enough sleep!"); } else if (total == 7 || total == { document.write("<p>Your score is average</p>"); } else { document.write("<p>Seek the advice of a sleep specialist without delay</p>"); } } </script> <script> $(document).ready(function() { $('form input:text').change(function() { $('#total').val(this.value).text(total); }); }); // end ready </script> and the image posted is the output. I need it to add up all the numbers in the text fields and spit them out. Right now it only wants to write that its a <span> tag. Link to comment https://forums.phpfreaks.com/topic/271455-using-change-function-to-update-value-of-text-fields/ Share on other sites More sharing options...
ahaberman25 Posted December 1, 2012 Author Share Posted December 1, 2012 I should have posted the entire snippet of code as well sorry sleep.html Link to comment https://forums.phpfreaks.com/topic/271455-using-change-function-to-update-value-of-text-fields/#findComment-1396727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.