checkbox slow motion?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1096 Views - Last Post: 11 January 2013 - 04:33 AM

#1 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

checkbox slow motion?

Posted 10 January 2013 - 09:08 PM

checkboxes take 1 minute to show as checked.

the problem went away after a few days. i did not really find the problem/solution. Now it comes back?

what can be the problem?
Is This A Good Question/Topic? 0
  • +

Replies To: checkbox slow motion?

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: checkbox slow motion?

Posted 10 January 2013 - 09:36 PM

Can you please post the code that you are having problem with? It will be helpful to find out which part of your program is causing the error.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: checkbox slow motion?

Posted 10 January 2013 - 09:47 PM

here is the page that is slow on IE, but not on firefox.

the page is relatively fast now (still takes 5 sec to show), but it can be very slow

This post has been edited by g37752: 10 January 2013 - 10:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: checkbox slow motion?

Posted 10 January 2013 - 09:51 PM

Well, you can always use setTimeOut function to reduce the delays.

regards,
Raghav

This post has been edited by raghav.naganathan: 10 January 2013 - 09:59 PM

Was This Post Helpful? 1
  • +
  • -

#5 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: checkbox slow motion?

Posted 10 January 2013 - 10:56 PM

the problem is it goes through 2700 checkbox to see if any of them is checked.

how do i speed it up?
and why firefox does not have the problem?
Was This Post Helpful? 0
  • +
  • -

#6 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: checkbox slow motion?

Posted 10 January 2013 - 11:10 PM

any part of the following can be made more efficient?

for(var i=0;i<c.length;i++){
   if(c[i].checked)
   {
       ....
   }
   str=selected.toString();
   document.getElementById("selected").innerHTML=str;	 
}


the loop length is 2700.
Was This Post Helpful? 0
  • +
  • -

#7 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: checkbox slow motion?

Posted 10 January 2013 - 11:22 PM

I did a small search and I came across this link.

Do take a look and see if it helps you.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#8 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: checkbox slow motion?

Posted 10 January 2013 - 11:38 PM

thanks, i did improve by moving stuff out of the loop.
Was This Post Helpful? 0
  • +
  • -

#9 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: checkbox slow motion?

Posted 10 January 2013 - 11:45 PM

Glad it helped you...:)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,232
  • Joined: 08-June 10

Re: checkbox slow motion?

Posted 11 January 2013 - 01:38 AM

View Postg37752, on 11 January 2013 - 07:10 AM, said:

any part of the following can be made more efficient?

for(var i=0;i<c.length;i++){
   // ...	 
}


the loop length is 2700.

1) never calculate the end condition (c.length) of a loop, if it doesn’t change (and the length keeps constant here).
for (var i = 0, l = c.length; i < l; i++)
for (var l = c.length; l--;​)

2) omitting whitespace does not make your code run faster, only less readable.

This post has been edited by Dormilich: 11 January 2013 - 01:39 AM

Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3473
  • View blog
  • Posts: 11,788
  • Joined: 12-December 12

Re: checkbox slow motion?

Posted 11 January 2013 - 03:20 AM

View Postg37752, on 10 January 2013 - 11:10 PM, said:

any part of the following can be made more efficient?

for(var i=0;i<c.length;i++){
   if(c[i].checked)
   {
       ....
   }
   str=selected.toString();
   document.getElementById("selected").innerHTML=str;	 
}


the loop length is 2700.


You haven't shown much code, but the last two lines could be

document.getElementById("selected").innerHTML = str selected + '';

but you should also do this before the loop:

var selec = document.getElementById("selected");
// then
selec.innerHTML = selected + '';


If, as it seems, you are setting the innerHTML repeatedly (within the loop) then only the last assignment will remain?! If you are only looking for the last selected (checked?) item then you should start at the end and work backwards, using break to break out of the loop.

I think you should show more of your code.

This post has been edited by andrewsw: 11 January 2013 - 03:40 AM

Was This Post Helpful? 0
  • +
  • -

#12 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,232
  • Joined: 08-June 10

Re: checkbox slow motion?

Posted 11 January 2013 - 03:23 AM

View Postandrewsw, on 11 January 2013 - 11:20 AM, said:

You haven't shown much code, but the last two lines could be
document.getElementById("selected").innerHTML = str + '';

what good does adding an empty string would have here? str is already a string.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3473
  • View blog
  • Posts: 11,788
  • Joined: 12-December 12

Re: checkbox slow motion?

Posted 11 January 2013 - 03:29 AM

View PostDormilich, on 11 January 2013 - 03:23 AM, said:

View Postandrewsw, on 11 January 2013 - 11:20 AM, said:

You haven't shown much code, but the last two lines could be
document.getElementById("selected").innerHTML = str + '';

what good does adding an empty string would have here? str is already a string.


I don't think it is necessary at all (especially if str is already a string) but I'm encouraging the OP not to use the (slow) function call toString(). Even if selected were a number it wouldn't be necessary. Oops, I meant:

document.getElementById("selected").innerHTML = selected + '';

This post has been edited by andrewsw: 11 January 2013 - 03:32 AM

Was This Post Helpful? 0
  • +
  • -

#14 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,232
  • Joined: 08-June 10

Re: checkbox slow motion?

Posted 11 January 2013 - 03:41 AM

I need to raise a point here. no matter which way of converting to string you use, if the variable doesn’t hold a string the .toString() method will always be used, whether directly or indirectly.
Was This Post Helpful? 1
  • +
  • -

#15 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3473
  • View blog
  • Posts: 11,788
  • Joined: 12-December 12

Re: checkbox slow motion?

Posted 11 January 2013 - 04:04 AM

@Dormilich
You're right! I had believed, for some reason, that a specific call to toString() is slower than + ''.

It even seems that (1234) + '' may even be slower than (1234).toString(), which seems strange.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2