473,396 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically total textbox and checkbox

Greetings,

I'm trying to calculate the total on an php page. I'm able to get the
checkbox portion to work properly but I'm having trouble with the
textbox "txtshipping". The default is 7.95 but if changes I need to
change the total.

How can I make the totalbox the default of the textbox of
"txtshipping"?

I struggle with javascript so any help would be greatly appreciate.

Thanks in advance.
Bird

<script type="text/javascript">

function gettotal(){

var tmp = 0;
var nBox = document.getElementsByName('chkboxpackage[]');
for(i=1; i<nBox.length+1; i++)
{
if (nBox[i-1].checked)
{
tmp += parseFloat(document.forms[0]['hdnPackage'+i].value);

}
}

var nBox2 = document.getElementsByName('chkboxitem[]');
for(i=1; i<nBox2.length+1; i++)
{
if (nBox2[i-1].checked)
{
tmp += parseFloat(document.forms[0]['hdnItem'+i].value);

}
}

tmp += parseFloat(document.forms[0]['txtshipping'].value);
document.forms[0].totalbox.value = tmp.toFixed(2);
}

</script>

<input type="checkbox" name="chkboxpackage[]" value="1"
onClick="gettotal()">
<input type="hidden" name="hdnPackage1"
value="69.95" >

<input type="checkbox" name="chkboxpackage[]" value="2"
onClick="gettotal()">
<input type="hidden" name="hdnPackage2"
value="49.95" >
<input type="checkbox" name="chkboxpackage[]" value="3"
onClick="gettotal()">
<input type="hidden" name="hdnPackage3"
value="495.00" >
<input type="checkbox" name="chkboxitem[]" value="1"
onClick="gettotal()">
<input type="hidden" name="hdnItem1"
value="89.95" >
<input type="checkbox" name="chkboxitem[]" value="2"
onClick="gettotal()">
<input type="hidden" name="hdnItem2"
value="99.95" >
<input type="checkbox" name="chkboxitem[]" value="3"
onClick="gettotal()">
<input type="hidden" name="hdnItem3"
value="149.95" >
<input name="txtShipping" type="text" size="15"
onChange="gettotal()"></td>
<input type="text" name="totalbox"
value="0.00" readonly/>

Mar 1 '07 #1
1 2023
"bird" <ma******@hughes.netwrote in
news:11*********************@p10g2000cwp.googlegro ups.com:
>
How can I make the totalbox the default of the textbox of
"txtshipping"?
?????? This doesn't make sense. Please explain in different words.
<input name="txtShipping" type="text" size="15"
onChange="gettotal()"></td>
?????? You want to calculate the total when the user changes the
shipping cost? Usually the user picks the shipping *method* and the
shipping cost is not in his control. For example, supposed I ordered
something large and heavy from you, and specified the shipping cost as
$1.00. That would be good for me, but bad for you. I suggest you re-
think this part.
Mar 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kea | last post by:
I have a checkbox and a textbox in a continuous taborder on a form along with a bunch of other controls. The textbox is disabled. When I leave the checkbox I want to enable the textbox and move...
0
by: Ellen Manning | last post by:
I've got an A2K form with a subform based on a query. This query has a checkbox and an amount field and returns records if checkbox is checked. I Dsum the amount field and display on the main...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
3
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes....
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
2
by: ssmith147 | last post by:
Hi, I'm somewhat familiar with access and vb programming (I can read someone else's code, for the most part), but I'm still very green when it comes to creating solutions for my own needs. I'm...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.