I have created a form in asp. I used for loop to create text fields, obviously each text fields will have same name. Now I want the sum of these input fields. The sum should be displayed in total imports ( by adding 2 imports ) and total duty forgone( by adding 2 duty forgone).
7 3035
You have multiple IDs which you should correct. IDs should be unique.
Anyway, if the name is the same for the ones that you need the sum of, use document.getElementsByName() to get all elements with the same name. Then loop over the collection and add them to a variable using parseInt/parseFloat to convert them to a number. Finally, set the total field to this value: - document.getElementById("tot_import").value = total;
See how you manage with that and if you get stuck, post your code.
Thanks for the replay ,
I tried with that code.great its working. here is the code - function DoSum1() //for looped sum
-
{
-
var TheSum = 0;
-
for (i=1; i<=5; i++) {
-
TheSum += parseFloat(document.getElementById("txtExp_Fy1" + i).value-0);
-
}
-
document.getElementById("txtExp_tot1").value = TheSum;
-
}
i was able to get the result for vertical columns but now the problem is to get the sum of horizontal i.e row wise total
You'd get it in a similar manner, but it depends on how you're naming/ID-ing your text box elements vertically.
Thanks for the replay again,
Dear sir,
Here is the code written in "ASP" , Please tell me "How i can find the sum of text fields horizontally. - <html>
-
<head>
-
<TITLE>EXIM - Progress Reports - Annual Details (Insert/Update) - Software Technology Parks Of India</title>
-
</HEAD>
-
<Body bgcolor="#FFFFFF" onload="return grand_tot();">
-
<Form Action="Annual9.asp" method=post Name=frm >
-
<Table border=1 cellspacing="0" cellpadding="0" align="center" width="60%" bgcolor=#F6E3CE>
-
<Tr Bgcolor=#DF7401>
-
<td height="22" Align="left" colspan=13>
-
<Font color="#111111" Face="Arial" Size="2">
-
<B>16(a). CG Import from the date of Inception up to 21.03.2010[all Amount Rs in Lakhs]</B>
-
</Font>
-
</td>
-
</Tr>
-
<tr Bgcolor=#DF7401>
-
<td width="3%" align="center" valign="middle" rowspan="2"><font size="2" face="Arial, Helvetica" class="content"><b>Sl.No</b></font></td>
-
<td width="20%" align="center" rowspan="2"><b>Imports Through </b></td>
-
<td width="20%" align="center" colspan="2"><b>As on 31.03.2009(From the Inception)</b></td>
-
<td width="20%" align="center" colspan="2"><b>During Financial Year 2009-10</b></td>
-
<td width="20%" align="center" colspan="2"><b>Total</b></td>
-
-
</tr>
-
<tr Bgcolor=#DF7401>
-
-
<td width="10%" align="center"><b>Import</b></td>
-
<td width="10%" align="center"><b>Duty Foregone</b></td>
-
<td width="10%" align="center"><b>Import</b></td>
-
<td width="10%" align="center"><b>Duty Foregone</b></td>
-
<td width="10%" align="center"><b>Import</b></td>
-
<td width="10%" align="center"><b>Duty Foregone</b></td>
-
</tr>
-
<%
-
-
Dim i
-
-
for i=1 to 10
-
-
if i=1 Then
-
%>
-
<tr >
-
<td width="3%" align="center">a</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Out right Purchase</b></font></td>
-
<%
-
elseIf i=2 then
-
%>
-
<tr >
-
<td width="3%" align="center">b</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Loan Basis</b></font></td>
-
<%
-
elseIf i=3 then
-
%>
-
<tr >
-
<td width="3%" align="center">c</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Free of Charge</b></font></td>
-
<%
-
elseIf i=4 then
-
%>
-
<tr >
-
<td width="3%" align="center">d</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>High Sea Sale</b></font></td>
-
<%
-
elseIf i=5 Then
-
%>
-
<tr >
-
<td width="3%" align="center">e</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Second Hand CG</b></font></td>
-
<%
-
elseIf i=6 then
-
%>
-
<tr >
-
<td width="3%" align="center">f</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Bond-Bond Transfer</b></font></td>
-
-
<%
-
elseIf i=7 then
-
%>
-
<tr >
-
<td width="3%" align="center">g</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Deemed Import</b></font></td>
-
-
<%
-
elseIf i=8 then
-
%>
-
<tr >
-
<td width="3%" align="center">h</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Import through courier mode</b></font></td>
-
<%
-
elseIf i=9 Then
-
%>
-
<tr >
-
<td width="3%" align="center">i</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Leasing of Capital Goods</b></font></td>
-
<%
-
elseIf i=10 Then
-
%>
-
<tr >
-
<td width="3%" align="center">j</td>
-
<td width="20%" align="center" valign="middle"><font size="1" face="Arial, Helvetica" class="content"><b>Permanent shifting from other units</b></font></td>
-
<%End If
-
%>
-
<td width=10% align=center> <input type=text name=txtExp_Fy11<%=i%> id="txtExp_Fy1" size=8 value="<%=Request("txtExp_Fy11"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" onkeypress="return validateint(event);"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
<td width=10% align=center> <input type=text name=txtExp_inc12<%=i%> id="txtExp_inc1" size=8 value="<%=Request("txtExp_inc12"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" onkeypress="return validateint(event);"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
<td width=10% align=center> <input type=text name=txtExp_Fy13<%=i%> id="txtExp_Fy1" size=8 value="<%=Request("txtExp_Fy13"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" onkeypress="return validateint(event);"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
<td width=10% align=center> <input type=text name=txtExp_inc14<%=i%> id="txtExp_inc1" size=8 value="<%=Request("txtExp_inc14"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" onkeypress="return validateint(event);"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
<td width=10% align=center> <input type=text name=txtExp_Fy15<%=i%> id="txtExp_Fy1" size=8 value="<%=Request("txtExp_Fy15"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" readonly="readonly" onkeypress="return validateint(event);" onblur="return DoSum33() ;"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
<td width=10% align=center> <input type=text name=txtExp_inc16<%=i%> id="txtExp_inc1" size=8 value="<%=Request("txtExp_inc16"&i&"")%>"
-
Onfocus="window.status='Enter Manpower from the day of inception' ;return true" readonly="readonly" onkeypress="return validateint(event);" onblur="return DoSum34() ;"
-
Onmouseover="window.status='Manpower from the day of inception'';return true;" Onmouseout="window.status='Insertion form';return true;">
-
</td>
-
</tr>
-
<%
-
next
-
%>
-
<tr align="center">
-
<td width="3%" align="center"><b>A</b></td>
-
<td width="20%" align="center" valign="middle"><font size="02" face="Arial, Helvetica" class="content"><b>Grand Total(a to j)</b></font></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_inc_import" size="8" onkeypress="return validateint(event);" readonly="readonly" ></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_inc_dutyforegone" size="8" onkeypress="return validateint(event);" readonly="readonly" ></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_during_import" size="8" onkeypress="return validateint(event);" readonly="readonly" ></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_during_dutyforegone" size="8" onkeypress="return validateint(event);" readonly="readonly" ></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_tot_import" size="8" onkeypress="return validateint(event);" readonly="readonly" "></td>
-
<td width="10%" ><input type="text" name="txt_grandtot_tot_foregone" size="8" onkeypress="return validateint(event);" readonly="readonly" "></td>
-
</tr>
-
</tr>
-
</Table>
-
</Body>
-
</html>
please check the attachement , you will get the clear picture what i real want to calculate. waiting for your replay ..........
See how you've used the ID here: - document.getElementById("txtExp_Fy1" + i)
Give the IDs of the elements going across similar style IDs, e.g. "textExp_Fy1_1", "textExp_Fy1_2" and so on, so then you can use a for loop to loop over them as you've done with the previous code.
Thaks a lot. I tried with the fallowing code .Its working. - function loopsum6() //to get the sum in horizontal way i.e alternate values
-
{
-
var count=1;
-
while(count<=2)
-
{
-
for (i=1; i<=2; i++)
-
{
-
if(count==1 && i==1)
-
{
-
var val1 = parseFloat(document.getElementById("txtExp_inc1289"+ i).value-0);
-
var val2 = parseFloat(document.getElementById("txtExp_inc1489"+ i).value-0);
-
var ansD = document.getElementById("txtExp_inc1689"+ i);
-
ansD.value = val1 + val2;
-
break;
-
}
-
if(count==2 && i==2)
-
{
-
var val1 = parseFloat(document.getElementById("txtExp_inc1289"+ i).value-0);
-
var val2 = parseFloat(document.getElementById("txtExp_inc1489"+ i).value-0);
-
var ansD = document.getElementById("txtExp_inc1689"+ i);
-
ansD.value = val1 + val2;
-
break;
-
}
-
}
-
count++;
-
}
-
}
That's not the most efficient piece of code - a lot of unnecessary bloat and redundancy.
PS. threads merged. Please keep all posts in one thread instead of starting a new thread each time!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: William C. White |
last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using
cURL? Our website is hosted on a shared drive and the webhost company
doesn't installed additional software (such as cURL)...
|
by: Albert Ahtenberg |
last post by:
Hello,
I don't know if it is only me but I was sure that header("Location:url")
redirects the browser instantly to URL, or at least stops the execution of
the code. But appearantely it continues...
|
by: James |
last post by:
Hi,
I have a form with 2 fields.
'A'
'B'
The user completes one of the fields and the form is submitted.
On the results page I want to run a query, but this will change
subject to which...
|
by: Ollivier Robert |
last post by:
Hello,
I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9
system. The link succeeds but everytime I try to run php, I get a SEGV from
inside the libcnltsh.so library.
...
|
by: Richard Galli |
last post by:
I want viewers to compare state laws on a single subject.
Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the...
|
by: Albert Ahtenberg |
last post by:
Hello,
I have two questions.
1. When the user presses the back button and returns to a form he filled
the form is reseted. How do I leave there the values he inserted?
2. When the...
|
by: inderjit S Gabrie |
last post by:
Hi all
Here is the scenerio ...is it possibly to do this...
i am getting valid course dates output on to a web which i have designed
....all is okay so far , look at the following web url
...
|
by: Jack |
last post by:
Hi All,
What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g.
select x from y where z=:parameter
Which in asp/jsp would be followed by some statements to bind a value...
|
by: Sandwick |
last post by:
I am trying to change the size of a drawing so they are all 3x3.
the script below is what i was trying to use to cut it in half ... I
get errors.
I can display the normal picture but not the...
|
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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |