total value on client side.

Is there a way on the client side to total up the quantity on every row in real time. what I have below and show in a label. if not in jquery even Javascript.
 
$(window).load(function() {
     $('input[id^="txtquantity"]').live('onkeyup', function() {
         if (String($(this).val()).length < 1) return false;
         

            });
        });

  <label></label>
<input type="text" id="txtquantity1" value="0" />
    <input type="text" id="txtquantity2" value="0" />
    <input type="text" id="txtquantity3" value="0" />
    <input type="text" id="txtquantity4" value="0" />
    <input type="text" id="txtquantity5" value="0" />
LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Like this?

var total=0,val;
$("input[name^='txtquantity').each(function() {
  val= $(this).val();
  total+=isNaN(val)?0:parseInt(val,10);
}
$("#result").val(total);
 
0
Seven priceFull StackAuthor Commented:
Ok I will give it a try.
0
Seven priceFull StackAuthor Commented:
keep getting error

    //<![CDATA[
     $(window).load(function() {
   
        $('input[id^="txtquantity"]').each(function() {
   var total=0,val;
$("input[name^='txtquantity').each(function() {
  val= $(this).val();
  total+=isNaN(val)?0:parseInt(val,10);
}
$("#result").val(total);
}
}

     
     //]]>
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Michel PlungjanIT ExpertCommented:
What error?
0
Seven priceFull StackAuthor Commented:
sorry my friend a still a student in jquery with the closing tags.

     $(window).load(function() {
   
        var total=0,val;
$('input[id^="txtquantity"]').each(function() {
  val= $(this).val();
  total+=isNaN(val)?0:parseInt(val,10);

}
$("#result").val(total);
});
0
Seven priceFull StackAuthor Commented:
ok i got the syntax but nothing

 //<![CDATA[
           $(window).load(function() {
               var total = 0, val;
               $('input[id^="txtquantity"]').each(function() {
                   val = $(this).val();
                   total += isNaN(val) ? 0 : parseInt(val, 10);
                   //  $("#result").val(total);
                   {
                       $("#result").val(total);
                   }
               });
           });
               
    //]]>


  <div id="results">dd</div>
0
Michel PlungjanIT ExpertCommented:
Sorry I was reading this on a mobile - not so easy to answer.

Try this
$(document).ready(function() {
  var inputs = $('input[id^="txtquantity"]')
  inputs.live('onkeyup', function() {
    var total=0,val;
    inputs.each(function() {
      val=$(this).val();
      total+=isNaN(val)?0:parseInt(val,10);
    });
    $("#result").text(total);
    if (String($(this).val()).length < 1) return false;
  });
});

Open in new window

0
Seven priceFull StackAuthor Commented:
confused now. I do not see the results you can remove

 if (String($(this).val()).length < 1) return false;

i am just trying to get the total
0
Michel PlungjanIT ExpertCommented:
You may get a scoping issue - I will go to bed now and if you need help I will try a jsfiddle.net tomorrow
0
Seven priceFull StackAuthor Commented:
ok sorry myself. but there is no error but I also do not see any results

<div id="results"></div>

why is that
0
Michel PlungjanIT ExpertCommented:
I lost the edit so I had to enter it again. Have a look again at
$(document).ready(function() {
  var inputs = $('input[id^="txtquantity"]')
  inputs.live('onkeyup', function() {
    var total=0,val;
    inputs.each(function() {
      val=$(this).val();
      total+=isNaN(val)?0:parseInt(val,10);
    });
    $("#result").text(total);
  });
});

Open in new window

0
HainKurtSr. System AnalystCommented:
here it is
<html>
<head>
			<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>
<script>
$(document).ready(function() {
//add functions here
	$('input[id^="txtquantity"]').live('keyup', function() {
		if (String($(this).val()).length < 1) return false;
		getSum();
	});
});
function getSum(){
	var s = 0;
	$('input[id^="txtquantity"]').each(function(){
		//alert($(this).val());
		s=s+$(this).val()*1;
	});
	$('#lblSum').html(s);
}
</script>
</head>

<body>

SUM : <label id=lblSum></label><br>
<input type="text" id="txtquantity1" value="0" />
<input type="text" id="txtquantity2" value="0" />
<input type="text" id="txtquantity3" value="0" />
<input type="text" id="txtquantity4" value="0" />
<input type="text" id="txtquantity5" value="0" />
    
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
I see but for some reason the edit is not working

test it here
http://jsfiddle.net/
0
HainKurtSr. System AnalystCommented:
mine looks similar to what is posted before :) with usage of isNaN and parseInt (copied from previous post) my solution is
<html>
<head>
			<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>
<script>
$(document).ready(function() {
//add functions here
	$('input[id^="txtquantity"]').live('keyup', function() {
		if (String($(this).val()).length < 1) return false;
		getSum();
	});
});
function getSum(){
	var s = 0;
	$('input[id^="txtquantity"]').each(function(){
		//alert($(this).val());
		var v = $(this).val();
		s=s+( isNaN(v) ? 0 : parseInt(v) );
	});
	$('#lblSum').html(s);
}
</script>
</head>

<body>

SUM : <label id=lblSum></label><br>
<input type="text" id="txtquantity1" value="0" />
<input type="text" id="txtquantity2" value="0" />
<input type="text" id="txtquantity3" value="0" />
<input type="text" id="txtquantity4" value="0" />
<input type="text" id="txtquantity5" value="0" />
    
</body>
</html>

Open in new window

0
Seven priceFull StackAuthor Commented:
tks
0
Michel PlungjanIT ExpertCommented:
Here - you were using the wrong event. it is keyup, not onkeyup

http://jsfiddle.net/mplungjan/Uvsrp/
$(document).ready(function() {
  var inputs = $('input[id^="txtquantity"]');
    inputs.live('keyup', function() {
    var total=0,val;
    inputs.each(function() {
      val=$(this).val();
      total+=isNaN(val)?0:parseInt(val,10);
    });
    $("#result").text(total);
  });
});

Open in new window

0
Michel PlungjanIT ExpertCommented:
Hmm, have to be VERY fast to keep up with the accepts here :O

Good night
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.