16 Replies - 673 Views - Last Post: 11 January 2013 - 04:33 AM
#1
checkbox slow motion?
Posted 10 January 2013 - 09:08 PM
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?
Replies To: checkbox slow motion?
#2
Re: checkbox slow motion?
Posted 10 January 2013 - 09:36 PM
regards,
Raghav
#3
Re: checkbox slow motion?
Posted 10 January 2013 - 09:47 PM
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
#4
Re: checkbox slow motion?
Posted 10 January 2013 - 09:51 PM
regards,
Raghav
This post has been edited by raghav.naganathan: 10 January 2013 - 09:59 PM
#5
Re: checkbox slow motion?
Posted 10 January 2013 - 10:56 PM
how do i speed it up?
and why firefox does not have the problem?
#6
Re: checkbox slow motion?
Posted 10 January 2013 - 11:10 PM
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.
#8
Re: checkbox slow motion?
Posted 10 January 2013 - 11:38 PM
#9
Re: checkbox slow motion?
Posted 10 January 2013 - 11:45 PM
regards,
Raghav
#10
Re: checkbox slow motion?
Posted 11 January 2013 - 01:38 AM
g37752, on 11 January 2013 - 07:10 AM, said:
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
#11
Re: checkbox slow motion?
Posted 11 January 2013 - 03:20 AM
g37752, on 10 January 2013 - 11:10 PM, said:
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 =
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
#12
Re: checkbox slow motion?
Posted 11 January 2013 - 03:23 AM
#13
Re: checkbox slow motion?
Posted 11 January 2013 - 03:29 AM
Dormilich, on 11 January 2013 - 03:23 AM, said:
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
#14
Re: checkbox slow motion?
Posted 11 January 2013 - 03:41 AM
#15
Re: checkbox slow motion?
Posted 11 January 2013 - 04:04 AM
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.
|
|

New Topic/Question
Reply


MultiQuote



|