my problem is that when i dont type anything into the quantity textbox my jquery function calc() does not work. this is because '' = NAN (not a number)
I have tried add this code in my calc() function on cart_actions.js, but with no luck... -
if(quantity.length === 0){
-
quantity = $(".quantity input", this).val(0);
-
-
}
-
all it does is set the value to zero on the textbox, but it does recognize it as a zero in the script, the prices return NAN (AddedQuantity AND totalPrice). I have been scratching my head for weeks please help :) i have done an alert(quantity) aswell and that came back zero, but still AddedQuantity AND totalPrice say NAN.
showcart.php -
-
<input type='text' name='quantity[$id]' size='3' value='$productQty' /><br /></td>
-
-
cart_actions.js -
$(function() {
-
-
$("#cart tr .quantity input").change(function() {
-
var id = $(this).attr("name").slice(9, -1);
-
var quantity = $(this).val();
-
-
-
$.ajax({
-
type: "GET",
-
url: "cart_action.php",
-
data: "quantity[" + id + "]=" + quantity,
-
success: function() {
-
var startColor = $("#cart tr .quantity input[name*=" + id + "]").parent().parent().hasClass("odd") ? "#eeeeee" : "#ffffff";
-
$("#cart tr .quantity input[name*=" + id + "]").parent().parent().find("td").animate({ backgroundColor: "#ff8" }, 100).animate({ backgroundColor: startColor }, 800);
-
calcPrice();
-
},
-
error: function() {
-
window.location("cart_action.php?quantity[" + id + "]=" + quantity);
-
}
-
});
-
});
-
-
-
function calcPrice() {
-
-
var totalPrice = 0;
-
var AddedQuantity = 0;
-
-
-
$("#cart tr .quantity").parent().each(function() {
-
var quantity = $(".quantity input", this).val();
-
if(quantity.length === 0){
-
quantity = $(".quantity input", this).val(0);
-
}
-
-
var unitPrice = $(".unit_price", this).text().slice(1);
-
-
var extendedPrice = quantity*unitPrice;
-
-
var extendedPriceZeros = extendedPrice.toFixed(2);
-
-
-
-
totalPrice += extendedPrice;
-
AddedQuantity += parseInt(quantity);
-
-
$(".extended_price", this).html("£" + extendedPrice.toFixed(2));
-
$("#total_price").html("£" + totalPrice.toFixed(2));
-
$("#test").html(AddedQuantity);
-
-
-
});
-
if ( totalPrice == 0 ) {
-
$("#cart").parent().replaceWith("<div id='container'><h1>Shopping Cart</h1><p>You have no items in your cart. Please <a href='home.php'>Continue to shop</a>!</p></div>");
-
}
-
if ( AddedQuantity >= 10 ) {
-
$("#cart td#shipping").html("Free !");
-
}
-
if ( AddedQuantity < 10 ) {
-
$("#cart td#shipping").html("£"+AddedQuantity*5);
-
}
-
-
-
}
-
});
-
-
hi
why dont you put 0 in the value attribute of the quantity by default ,and then use this method, - <input type="text" onblur='if(this.value==""){this.value=0;}'>
, i hope i got your problem right.
apart in your existing code , add parseInt() to the line number 38 where you are multiplying the quantity with price. - var extendedPrice = parseInt(quantity)*parseInt(unitPrice);
regards,
Omer Aslam
4 10064
hi
why dont you put 0 in the value attribute of the quantity by default ,and then use this method, - <input type="text" onblur='if(this.value==""){this.value=0;}'>
, i hope i got your problem right.
apart in your existing code , add parseInt() to the line number 38 where you are multiplying the quantity with price. - var extendedPrice = parseInt(quantity)*parseInt(unitPrice);
regards,
Omer Aslam
the problem is line 33. if you re-set quantity, it becomes a JQuery object (while $(…).val() is a number), which on line 38 will produce NaN.
for the calculation itself it would suffice to set quantity to 0.
@Omer: parseInt(JQuery) => NaN
thank you i have added onblur='if(this.value==""){this.value=0;}' and got rid of line -
if(quantity.length === 0){
-
quantity = $(".quantity input", this).val(0);
-
}
-
it now seems to work, is there anything else im missing or should that be ok?
hi luke ,
look at Dormilich last post, what he said is to be considered, but if you have removed that line its fine i think, and please select the correct answer which resolved your conflict so that any other person with the same issue who comes googling around could have help too.
regards,
Omer Aslam
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ian D |
last post by:
Firstly apologies for the convoluted question. I found this problem whilst
building a larger database. I've distilled it down to as small as possible
and can send a 200k example to anyone who has...
|
by: Terry Bickle |
last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4
macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB.
I'm sure there is a simple Access 101...
|
by: Lyn |
last post by:
Hi,
Can anyone tell me how the initial value displayed in Combo Box is
determined when a form is opened?
I am loading the dropdown from one field ("CategoryName") of a table, with
"ORDER BY ". ...
|
by: Shiye |
last post by:
Help...!
Hi all,
Does any of you know how can determine the default value of a filed to
be taken from another feild (already filled) in the same row of the
table???
Thanks,
Shai
|
by: Eduardo78 |
last post by:
I would like to set the default value of a combobox to "nothing" or spaces
when my form loads. I am using the dropdown list property becasue i want the
end-user to select only values listed in the...
|
by: Eduardo78 |
last post by:
I need to have a control where the default value equals nothing, and if an
user enters a value It validates that it is a date, if not show an error
message or advertise that only dates are allowed....
|
by: harry |
last post by:
Using aspnet20 csharp, I have a simple data entry screen that inserts
submitted values to a database. I want a default value to be submitted if no
value is entered in a textbox.
Thanks
_harry
|
by: Eric |
last post by:
Hi Everyone,
I'm writing a UserControl that exposes a property of the type
System.Drawing.Image, like this:
Public Property DefaultImage() As Image
Get
Return propDefaultImage
End Get...
|
by: Del |
last post by:
I have a form call frmMMD-PCKR. This form has seven buttons, each
button represents a part. When I click on any of the buttons they open
another form called frmTallyTagMMDPCKR.
On the...
|
by: phpuser123 |
last post by:
I want to display my string str as the defaultinput value and when I run ,oly the first part of the word is displayed. It skips everything after the blank space.How do I sort this out?
<%
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |