473,545 Members | 318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CPU 100% on a Loop while retrieving form values

Hi,

i have a simple problem. i have a form with a lot's of number of Text
and Hidden Fields. I just do a simple loop to get each value for each
attribute. I have about more than 2000.

if i do something simple like :

for (var i=0; i<2000; i++)
aValue = i+10;

it runs well. But if i do something like
for (var i=0; i<2000; i++)
aValue = document.myForm .elements[i].value;

it gives me 100% CPU for a long time before i submit the form.

Cheers,

Kant.
Jul 20 '05 #1
3 1606
"Kant" <ka******@hotma il.com> wrote in message
news:7e******** *************** ***@posting.goo gle.com...
i have a simple problem. i have a form with a lot's of number
of Text and Hidden Fields. I just do a simple loop to get each
value for each attribute. I have about more than 2000.

if i do something simple like :

for (var i=0; i<2000; i++)
aValue = i+10;

it runs well. But if i do something like
for (var i=0; i<2000; i++)
aValue = document.myForm .elements[i].value;

it gives me 100% CPU for a long time before i submit the form.


It is very inefficient to resolve document.myForm .elements 2000 times.
Compare it with:-

var els = document.forms['myForm'].elements;
for(var c = 0; c < 2000;c++){
aValue = els[c].value;
}

But looking up properties on 2000 object is going to be relatively slow
however you do it.

Richard.
Jul 20 '05 #2
Lee
Kant said:

Hi,

i have a simple problem. i have a form with a lot's of number of Text
and Hidden Fields. I just do a simple loop to get each value for each
attribute. I have about more than 2000.

if i do something simple like :

for (var i=0; i<2000; i++)
aValue = i+10;

it runs well. But if i do something like
for (var i=0; i<2000; i++)
aValue = document.myForm .elements[i].value;

it gives me 100% CPU for a long time before i submit the form.


Move as much as possible to outside the loop:

var myElements=docu ment.myForm.ele ments;
for(var i=0;i<2000;i++) {
aValue=myElemen ts[i].value;
}

Slightly more efficient, but probably not practical in whatever
you're really doing:

var myElements=docu ment.myForm.ele ments;
for(var i=0;i<2000;aVal ue=myElements[i++].value);

Jul 20 '05 #3
Ok thanks a lot guys :D

it works fine !!!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

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

Similar topics

8
4042
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per cent. Even if i remove the mysql insert query and just loop through the file , it still hits 100 per cent CPU. This has the knock on effect of slowing...
3
1629
by: Shiraj | last post by:
I have a problem, I can display some text 5 times using a loop and i want to pass those printed values to another page when i clicked send button.if you know the method please email me. thank you. (pooja_blacktulip@yahoo.com) ----------------------------- This message is posted by http://asp.forumszone.com
9
2223
by: Br | last post by:
In an Access2000 project (ADP) I have a form whose recordsource is a stored procedure in SQL. On the OnOpen event I run a simple piece of code to move to a record based on a value on another already open form. The code fails because the RecordsetClone is only retrieving the first 100 records. If you put a break in the code and trace through it...
3
15070
by: giant food | last post by:
This seems like a long shot, but I wondered if there's a way to loop over the values in an Enum. For example, say I have an Enum as follows: Public Enum statusValues Ready Running Finished Error End Enum
1
1530
by: Captain Dondo | last post by:
I am not really experienced in Javascript so bear with me.... I am working with an embedded platform; no mouse, no keyboard. Just up, down, left, right keys and +/- keys for incrementing/decrementing the vaules in the form. So my website consists of forms... Each form has a number of columns and rows. I am generating each page using a...
10
3658
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
2
9421
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the soccer clubs which he will be coaching; thus he can select only one soccer club for a new coach or multiple soccer clubs. This is how I am trying it:...
4
1810
vikas251074
by: vikas251074 | last post by:
Loop runs indefinite times. suppose v_router = 5 is entered by user, then following code runs indefinite times i.e. record is inserted indefinite times though each have different i and v_ip_address. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta...
1
1075
by: pfildes | last post by:
Hi, I am pretty new to VB.net and am having trouble figuring out how to do this. I have an app that copies data from one datasource to another. I have it set to run through a for loop for each row in SourceDataTable. for each row i get the a value that is not an ID and I have a funciton that compares this to a column in the...
0
7648
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7743
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5319
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3441
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3437
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1867
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 we have to send another system
0
692
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.