Jump to content

Using .change Function To Update Value Of Text Fields


ahaberman25

Recommended Posts

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.

post-134159-0-15651000-1354393682_thumb.jpg

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.