Hi there.
I have this Function: -
-
//Funzione Calcola
-
-
function calcola(frmObj, id)
-
-
{
-
-
-
//Somma Totale Imponibile
-
-
var somma_totale_imponibile = 0;
-
var nelementi = ["Totale_imponibile_" + id].length ;
-
-
for ( var n = 0; n <= nelementi; n++ )
-
-
{
-
n = parseFloat(frmObj["Totale_imponibile_" + id].value);
-
somma_totale_imponibile += ((isNaN(parseFloat(n)))?0:parseFloat(n));
-
alert(n)
-
}
-
-
alert("Totale_imponibile_" + id)
-
alert(somma_totale_imponibile)
-
-
frmObj.somma_totale_imponibile.value = somma_totale_imponibile.toFixed(2);
-
-
-
//chiusura funzione calcola
-
}
-
-
I require this datum:
Totale_imponibile_1 = 3
Totale_imponibile_2 = 50
Totale_imponibile_3 = 2
somma_totale_imponibile = 55
It doesn't work.
Can anyone help?
Thanks, regards
Viki
19 3277 gits 5,390
Expert Mod 4TB
hi ...
welcome to TSDN ...
i think that doesn't work the way you intended. please show your html relating to this problem too ... because i assume nelementi should be a number of textboxes contained by your form?
kind regards
hi
well,I think there's a logical error in your code,but I can see what you want to do.so I write a code for you.I hope it's you want.
[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form id="form1">
<input type="text" id="Totale_imponibile_1" value="50" /><br />
<input type="text" id="Totale_imponibile_2" value="2" /><br />
<input type="text" id="Totale_imponibile_3" value="3" /><br />
<input type="text" id="somma_totale_imponibile" value="" /><br />
<input type="button" value="Sum Up" onClick="calcola(3);" />
</form>
</body>
<script language="javascript">
function calcola(length)
{
//Somma Totale Imponibile
var somma_totale_imponibile = 0;
for ( var id = 1; id <= length; id++ )
{
var temp = document.getElementById("Totale_imponibile_" + id).value;
if (isNaN(temp) == false)
somma_totale_imponibile += parseFloat(temp);
}
//alert(somma_totale_imponibile);
document.getElementById("somma_totale_imponibile") .value = somma_totale_imponibile.toFixed(2);
}
</script>
</html>
[/HTML]
hope it helps.
Can anyone help?
Regards
Viki
You're still starting at 0 in your loop. The first number should be 1.
Thanks, but not work: - <script language="javascript">
-
<!--
-
-
-
//Funzione Calcola
-
-
function calcola(frmObj, id)
-
{
-
-
//Totale Imponibile
-
frmObj["Totale_imponibile_" + id].value = parseFloat(frmObj["quantita_" + id].value) *
-
parseFloat(frmObj["imponibile_meno_sconto_" + id].value);
-
frmObj["Totale_imponibile_" + id].value = parseFloat(frmObj["Totale_imponibile_" + id].value).toFixed(2);
-
-
-
//Totale IVA
-
frmObj["Tot_iva_" + id].value = ((parseFloat(frmObj["Totale_imponibile_" + id].value)/100) *
-
parseFloat(frmObj["Iva_" + id].value));
-
frmObj["Tot_iva_" + id].value = parseFloat(frmObj["Tot_iva_" + id].value).toFixed(2);
-
-
-
//Somma Totale Imponibile
-
-
var somma_totale_imponibile = 0;
-
var nelementi = ["Totale_imponibile_" + id].length ;
-
-
for ( var n = 1; n <= nelementi; n++ )
-
-
{
-
n = parseFloat(frmObj["Totale_imponibile_" + id].value);
-
somma_totale_imponibile += ((isNaN(parseFloat(n)))?0:parseFloat(n));
-
-
}
-
-
alert("Totale_imponibile_" + id)
-
alert(somma_totale_imponibile)
-
-
frmObj.somma_totale_imponibile.value = somma_totale_imponibile.toFixed(2);
-
-
-
-
//chiusura funzione calcola
-
}
-
-
// -->
-
</script>
nelementi is not set correctly. Set that using the number of rows in the table or just use 9 (if its going to remain fixed).
In the for loop, use another variable name besides "n". You've already used it for indexing. Replace "id" with "n", so that you're not just accessing the same text box each time.
Nothing... no work: -
<script language="javascript">
-
<!--
-
-
-
//Funzione Calcola
-
-
function calcola(frmObj, id)
-
{
-
-
//Totale Imponibile
-
frmObj["Totale_imponibile_" + id].value = parseFloat(frmObj["quantita_" + id].value) *
-
parseFloat(frmObj["imponibile_meno_sconto_" + id].value);
-
frmObj["Totale_imponibile_" + id].value = parseFloat(frmObj["Totale_imponibile_" + id].value).toFixed(2);
-
-
-
//Totale IVA
-
frmObj["Tot_iva_" + id].value = ((parseFloat(frmObj["Totale_imponibile_" + id].value)/100) *
-
parseFloat(frmObj["Iva_" + id].value));
-
frmObj["Tot_iva_" + id].value = parseFloat(frmObj["Tot_iva_" + id].value).toFixed(2);
-
-
-
//Somma Totale Imponibile
-
-
var somma_totale_imponibile = 0;
-
var nelementi = ["Totale_imponibile_" + id].length ;
-
-
for ( var n = 1; n <= nelementi; n++ )
-
-
{
-
n = parseFloat(frmObj["Totale_imponibile_" + n].value);
-
somma_totale_imponibile += ((isNaN(parseFloat(n)))?0:parseFloat(n));
-
-
}
-
-
alert("Totale_imponibile_" + id)
-
alert(somma_totale_imponibile)
-
-
frmObj.somma_totale_imponibile.value = somma_totale_imponibile.toFixed(2);
-
-
-
-
//chiusura funzione calcola
-
}
-
-
// -->
-
</script>
-
-
You've not made the changes.
On line 25, you're setting nelementi.
On lines 30-31, you will also need to make changes as I described earlier.
Yuo write:
In the for loop, use another variable name besides "n". You've already used it for indexing. Replace "id" with "n", so that you're not just accessing the same text box each time. -
for ( var n = 1; n <= nelementi; n++ )
-
-
{
-
x = parseFloat(frmObj["Totale_imponibile_" + n].value);
-
somma_totale_imponibile += ((isNaN(parseFloat(x)))?0:parseFloat(x));
-
-
}
-
-
What I do not understand ?
Thanks
Try using 9 instead of nelementi, so that you can at least test that it's working.
In your latest code, on line 5, you don't need to parseFloat it again because that has already been done on the previous line.
Try using 9 instead of nelementi, so that you can at least test that it's working.
Not working.
In your latest code, on line 5, you don't need to parseFloat it again because that has already been done on the previous line.
-
for ( var n = 1; n <= nelementi; n++ )
-
-
{
-
n = parseFloat(frmObj["Totale_imponibile_" + id].value);
-
somma_totale_imponibile += n;
-
-
}
-
-
alert("Totale_imponibile_" + id)
-
alert(somma_totale_imponibile)
-
-
frmObj.somma_totale_imponibile.value = somma_totale_imponibile.toFixed(2);
-
Not working.
Sorry.
OK, try this: -
for ( var n = 1; n <= 9; n++ )
-
{
-
x = parseFloat(frmObj["Totale_imponibile_" + n].value);
-
somma_totale_imponibile += ((isNaN(x))?0:x);
-
}
Ok this work thanks; but nelementi it is not always fixed 9.
It is a variable in the code...
Ok this work thanks; but nelementi it is not always fixed 9.
It is a variable in the code...
Yes, I know that, but at least one problem is fixed.
To make nelementi variable, use the table's rows[] array: - var nelementi = document.getElementById("tableid").rows.length-2;
Sorry, but not working... -
var somma_totale_imponibile = 0;
-
//var nelementi = ["Totale_imponibile_" + id].length ;
-
var nelementi = document.getElementById("Totale_imponibile_").rows.length-2;
-
-
for ( var n = 1; n <= nelementi; n++ )
-
-
{
-
x = parseFloat(frmObj["Totale_imponibile_" + n].value);
-
somma_totale_imponibile += ((isNaN(x))?0:x);
-
}
-
-
alert("Totale_imponibile_" + id)
-
alert(somma_totale_imponibile)
-
-
frmObj.somma_totale_imponibile.value = somma_totale_imponibile.toFixed(2);
-
You're using the wrong id. The table id according to the source code is "table3".
Yes, this working !!!!!
You magician !!!
many thanks
Viki1967
No problem, you're welcome. I've been called many things, but never a magician!
Post again if you have any more questions.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Aaron Prohaska |
last post by:
I have just run into a problem where I have a page that posts back to
itself to execute code, except when the page does the post back it
somehow executes code that is in our home page for the site....
|
by: Federico Bari |
last post by:
Good morning all from italy,
i have probably a compatibility problem with a html/javascript page.
The aim of the code of the file test.htm you find here following (copy the
3 files in the...
|
by: Covad |
last post by:
Hi all,
For some reason my change() function is only called when the page loads. I'd
much rather it gets called when the select changes.
Here's the code:
window.onload = init;
function...
|
by: JesusFreak |
last post by:
From: us_traveller@yahoo.com (JesusFreak)
Newsgroups: microsoft.public.scripting.jscript
Subject: toolbar script problem
NNTP-Posting-Host: 192.92.126.136
Recently, I downloaded the following...
|
by: rdlebreton |
last post by:
Hi, Folks!
I've been trying to develop my own version of these draggable
layers and I have been limiting myself to IE6...for now. I have
looked at some other examples to get ideas of creating...
|
by: Jeff S |
last post by:
In a VB.NET code behind module, I build a string for a link that points to a
JavaScript function. The two lines of code below show what is relevant.
PopupLink = "javascript:PopUpWindow(" &...
|
by: ged |
last post by:
Hi,
i am a oo (c#) programmer, and have not used javascript for a while and
i cant work out how javascript manages its references. Object
References work for simple stuff, but once i have an...
|
by: mostafahamdyfcis |
last post by:
Hello all
I have used the sample code which exist in the following URL:
http://www.eggheadcafe.com/articles/javascript_modal_dialog.asp
which create modal dialog box, but some problem...
|
by: sorobor |
last post by:
dear sir ..
i am using cakephp freamwork ..By the way i m begener in php and javascript ..
My probs r bellow
I made a javascript calender ..there is a close button ..when i press close button...
|
by: jessy |
last post by:
Hi,
I have a problem with my DateTimePicker javascript code which i downloaded , the problem is when i pick the date and the date appears in my Text Field and i click Submit the date which i picked...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |