Seven price
asked on
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()).len gth < 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" />
$(window).load(function() {
$('input[id^="txtquantity"
if (String($(this).val()).len
});
});
<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" />
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
keep getting error
//<![CDATA[
$(window).load(function() {
$('input[id^="txtquantity" ]').each(f unction() {
var total=0,val;
$("input[name^='txtquantit y').each(f unction() {
val= $(this).val();
total+=isNaN(val)?0:parseI nt(val,10) ;
}
$("#result").val(total);
}
}
//]]>
//<![CDATA[
$(window).load(function() {
$('input[id^="txtquantity"
var total=0,val;
$("input[name^='txtquantit
val= $(this).val();
total+=isNaN(val)?0:parseI
}
$("#result").val(total);
}
}
//]]>
What error?
ASKER
sorry my friend a still a student in jquery with the closing tags.
$(window).load(function() {
var total=0,val;
$('input[id^="txtquantity" ]').each(f unction() {
val= $(this).val();
total+=isNaN(val)?0:parseI nt(val,10) ;
}
$("#result").val(total);
});
$(window).load(function() {
var total=0,val;
$('input[id^="txtquantity"
val= $(this).val();
total+=isNaN(val)?0:parseI
}
$("#result").val(total);
});
ASKER
ok i got the syntax but nothing
//<![CDATA[
$(window).load(function() {
var total = 0, val;
$('input[id^="txtquantity" ]').each(f unction() {
val = $(this).val();
total += isNaN(val) ? 0 : parseInt(val, 10);
// $("#result").val(total);
{
$("#result").val(total);
}
});
});
//]]>
<div id="results">dd</div>
//<![CDATA[
$(window).load(function() {
var total = 0, val;
$('input[id^="txtquantity"
val = $(this).val();
total += isNaN(val) ? 0 : parseInt(val, 10);
// $("#result").val(total);
{
$("#result").val(total);
}
});
});
//]]>
<div id="results">dd</div>
Sorry I was reading this on a mobile - not so easy to answer.
Try this
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;
});
});
ASKER
confused now. I do not see the results you can remove
if (String($(this).val()).len gth < 1) return false;
i am just trying to get the total
if (String($(this).val()).len
i am just trying to get the total
You may get a scoping issue - I will go to bed now and if you need help I will try a jsfiddle.net tomorrow
ASKER
ok sorry myself. but there is no error but I also do not see any results
<div id="results"></div>
why is that
<div id="results"></div>
why is that
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>
ASKER
tks
Here - you were using the wrong event. it is keyup, not onkeyup
http://jsfiddle.net/mplungjan/Uvsrp/
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);
});
});
Hmm, have to be VERY fast to keep up with the accepts here :O
Good night
Good night
ASKER