473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to add a checkbox value to totalsum

RayTracy
2 New Member
I´m trying to add a value to totalsum when checking a checkbox.
But I'm a n00b at this and I can't find any relevant information on the Internet to help me with my little problem.
I'm only including the relevant part of the script since it is way way long and the only thing that differs is the different artnr.
The + 60 in the last line is for shipping and handling so it should be left there as is.
The text in bold is what I can't get working...

I'm using JavaScript and so far the script looks like this:

<script language="JavaScript">

function calculate(){
var totalsum = 0;
if(!isNaN(parseInt(document.forms[0].artnr110.value))){
totalsum=totalsum + parseInt(document.forms[0].artnr110.value)*199;
document.forms[0].sum110.value = parseInt(document.forms[0].artnr110.value)*199;
}
if(!isNaN(parseInt(document.forms[0].extra.checked))){
totalsumma=totalsumma + parseInt(document.forms[0].extra.checked)*1;
}


document.forms[0].summa.value = totalsumma + (60) + " :-";
}
</script>

These are some values I have in my form:
<form name="order" action="order.asp" method="POST">

<INPUT TYPE="TEXT" SIZE="2" NAME="artnr110"
id="artnr110" onChange="calculate()">

<INPUT TYPE="TEXT" SIZE="2" NAME="sum110"
id=sum110 readonly>

<INPUT TYPE="TEXT" SIZE="3" NAME="sum"
id=sum width="20">

<INPUT TYPE="checkbox" NAME="extra" VALUE="50"
id=extra onClick="calculate()">

<input type="submit" value="send" name="order" />

</form>

I got everything but that checkbox to work. I tried around with different settings but beeing a n00b has it's limitations... ;)

Thanks in advance for help.
Ray
Jun 14 '07 #1
2 3377
epots9
1,351 Recognized Expert Top Contributor
Hi RayTracy welcome to TSDN

in your if statement your checking to see if the checkbox was checked, so its returning a true or false and your parsing it, what u want is to get the value:

Expand|Select|Wrap|Line Numbers
  1. if(!isNaN(parseInt(document.forms[0].extra.value))){
  2. totalsumma=totalsumma + parseInt(document.forms[0].extra.checked)*1;
  3. }
  4.  
good luck
Jun 14 '07 #2
RayTracy
2 New Member
Hi RayTracy welcome to TSDN

in your if statement your checking to see if the checkbox was checked, so its returning a true or false and your parsing it, what u want is to get the value:

Expand|Select|Wrap|Line Numbers
  1. if(!isNaN(parseInt(document.forms[0].extra.value))){
  2. totalsumma=totalsumma + parseInt(document.forms[0].extra.checked)*1;
  3. }
  4.  
good luck

Thank you for trying to help me. Much appreciated.
However, when changing to the suggested code all of the sudden I got NaN in my totalsum. I know NaN is Not a Number, but the value of extra = 1 so how in the heck can it become NaN?

If I delete the value of extra, then the calculation is correct, however without the value I want added, ofcourse.

Any suggestions, anyone?

\\Ray
Jun 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9723
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
11
1535
by: Jack | last post by:
I have a asp form where among others there are few text boxes and one check box. The checkbox is to indicate whether the entry is final. The checkbox is attahced to a field in table of type...
0
2235
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
34
3747
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
6
1937
by: nasirmajor | last post by:
dear all, i have a datagrid with checkboxes for selection of rows. and want to get unique id/ids(job_code) from the selected rows in array etc. can anyone help. <asp:datagrid id="dgResults"...
0
4077
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
2018
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
0
3089
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
1
12644
by: QuickBooksDev | last post by:
VB.NET 2005 DataGridView Checkbox - Check Event need to know check status I would like to use the DataGridView Checkbox like a normal checkbox. When someone clicks on it I would expect that I...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.