473,396 Members | 1,846 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.

Get the sum of inputted values on dynamic input box

Hello Everybody I have a dynamic check box input box and I want to compute the value of the input box, in every checked box Here is my HTML code

a=(-1)
Do until objRSDefect1.eof or a = RecFound
a = a + 1
%>
<tr>
<td>
<input type=checkbox name=chkDefect value=<%=objRSDefect1("iDefectId")%>> <%=objRSDefect1("vcDefect")%>
</td>

<td><input type=text name = "<%="txtNoofDefects" & a%>" onBlur=ReviewDefects()>
</td>
</tr>
<%objRSDefect1.Movenext
Loop


and here is my javascript which is incomplete coz i Dont what to do next
function ReviewDefects()
{
for (i=0; i < elements['txtNoOfDefects'].length; i++)


}


Thanks in advance!
Feb 16 '07 #1
15 5630
Hello everybody,

I need to compute to get sum of the inputted value using Javascript(please see below), please check what is wrong on my code, when i write into alert the message is undefine2, undefine23 --number 2 and 3 is the value inputted on text box, please see also my html code

function ReviewDefects()
{
with(document.form)
{
var intDefects;
for (i=0; i < txtReject.value - 1; i++)

intDefects += (elements['txtNoofDefects' + i].value);


alert(intDefects)


if (TotalDef != txtReject.value)

hidAction.value='Defects'
submit()

HTML CODE:
<%
a=(-1)
Do until objRSDefect1.eof or a = RecFound
a = a + 1
%>
<tr>
<td ><%=objRSDefect1("vcDefect")%>
</td>
<td ><input type=text name = "<%="txtNoofDefects" & a%>" value="<%=Request("txtNoofDefects" & a)%>"onChange=ReviewDefects()>
</tr>
<%objRSDefect1.Movenext
Loop

THanks
Feb 16 '07 #2
dorinbogdan
839 Expert 512MB
I'm not sure if understood the question.
In order to fill values in textboxes you can set
document.getElementsByName(i + "a").value with the desired value.

For more help, please provide more details.
Feb 16 '07 #3
dorinbogdan
839 Expert 512MB
Use :
intDefects += document.getElementsByName('txtNoofDefects' + i).value;
Feb 16 '07 #4
Use :
intDefects += document.getElementsByName('txtNoofDefects' + i).value;
I got this error

getElementsByName is undefined

THanks
Feb 16 '07 #5
dorinbogdan
839 Expert 512MB
Yes, you are right, I forgot the index:

intDefects += document.getElementsByName('txtNoofDefects' + i)[0].value

Or, you can use getElementById("idvalue").value, in that case you should set the id attribute of the input text control.
Feb 16 '07 #6
acoder
16,027 Expert Mod 8TB
Threads merged.
Feb 16 '07 #7
Hello i got the same error, when i tried the first one, i got this message underfined2, then entered another number on 2nd input box then it return undefined23 and so no on...

while the secod one, the error is undefined222, 2 is the number inputted, when i tried to input the second number, undefined222 error


Yes, you are right, I forgot the index:

intDefects += document.getElementsByName('txtNoofDefects' + i)[0].value

Or, you can use getElementById("idvalue").value, in that case you should set the id attribute of the input text control.
Feb 19 '07 #8
Thanks, I got It, I need to convert it to integer......Your help is highly appreciated...


Yes, you are right, I forgot the index:

intDefects += document.getElementsByName('txtNoofDefects' + i)[0].value

Or, you can use getElementById("idvalue").value, in that case you should set the id attribute of the input text control.
Feb 19 '07 #9
dorinbogdan
839 Expert 512MB
You can convert to int using the javascript function:

parseInt(intDefects)
Feb 19 '07 #10
Yes I used parseInt...How can I set the focus to next input box after I've entered the 1st number, just like this

for (i=0; i < 26; i++)
{
if (document.getElementById("txtNoofDefects" + i ).value != '' )

intDefects += parseFloat(document.getElementById("txtNoofDefects " + i ).value);


}

txtTotal.value = intDefects

document.getElementById("txtNoofDefects" + i ).focus()

I got an error on this "document.getElementById("") is null or not an object, please help...Thanks

You can convert to int using the javascript function:

parseInt(intDefects)
Feb 19 '07 #11
dorinbogdan
839 Expert 512MB
Please make sure that the input text haing id = ("txtNoofDefects" + i) exists.
It seems that at the end of the for loop i = 26.

Do you have that input text haing id = "txtNoofDefects26" ?
Feb 19 '07 #12
acoder
16,027 Expert Mod 8TB
Please make sure that the input text haing id = ("txtNoofDefects" + i) exists.
It seems that at the end of the for loop i = 26.

Do you have that input text haing id = "txtNoofDefects26" ?
That should be 25.
Feb 19 '07 #13
dorinbogdan
839 Expert 512MB
Yes, the last "for" iteration is executed on i = 25, then i becomes 26 and gets out.

Try this test:
[HTML]
<html>
<head>
<script language="JavaScript">
window.onload = function(){
for (i=0;i<26;i++){
window.status = i
}
alert(i);
}
</script>
</head>
<body>
</body>
</html>
[/HTML]

Or, am I missing something?
Feb 20 '07 #14
acoder
16,027 Expert Mod 8TB
Yes, the last "for" iteration is executed on i = 25, then i becomes 26 and gets out.
Yes, you're right. Looking at the code, yes, the focus is being given to an element with id "txtNoofDefects26" which probably doesn't exist.
Feb 20 '07 #15
acoder
16,027 Expert Mod 8TB
How can I set the focus to next input box after I've entered the 1st number
Depends how you want to do that. Is it after a maximum number of characters are pressed, then you can use this example. Alternatively, you can pass (in this function), an index which you can use instead of i.
Feb 20 '07 #16

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

Similar topics

1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
4
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through...
2
by: ayende | last post by:
I've a very strange issue here. I've this JS code: var hidden = document.createElement('input') //hidden.type='hidden'; hidden.value = getIdForUser(userTag)...
2
by: bryan.a.fowler | last post by:
I'm really new working with VB.net and I'm working on a simple program with a date input. I've got a couple of questions; 1) I'm using a DateTimePicker to show both the user inputted date as...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
1
by: joestevens232 | last post by:
I need help with my program. Im trying to take input from a file and store the input into different arrays in my structure. The first pary where I get the students name worked fine but now when i try...
1
by: Ben Brown | last post by:
I'm having some problems.. I have some javascript generated input elements with dynamic names and values. ex: <input name = "t1Name" .../> <input name = "t2Name" .../> ..... <input name =...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.