Connecting Tech Pros Worldwide Help | Site Map

HELP: Slow response in checkbox using javascript and ajax

Newbie
 
Join Date: Oct 2009
Posts: 5
#1: Oct 6 '09
Hi everyone. Im trying to optimize a website. But im stuck with this code here. My problem is when i check/uncheck the checkbox it took 5-6 sec just by clicking it. Could anyone help me rewrite this code?. please

Expand|Select|Wrap|Line Numbers
  1. function checkAccess(celDiv,id)
  2. {
  3.     var celValue = $(celDiv).html();
  4.  
  5.     if (celValue==1) $(celDiv).html("<input type='checkbox' value='"+$(celDiv).html()+"' checked disabled>")//display detFlex1
  6.     else $(celDiv).html("<input type='checkbox' value='"+$(celDiv).html()+"' disabled>")//convert value of checkbox to 0/1    
  7.  
  8.     $(celDiv).click
  9.     (
  10.          function()
  11.         {
  12.             $('input',this).each(
  13.                  function(){
  14.  
  15.                     tr_idx = $('#detFlex1 tbody tr').index($(this).parent().parent().parent());    
  16.                     td_idx = $('#detFlex1 tbody tr:eq('+tr_idx+') td').index($(this).parent().parent());
  17.                     td_last = 13;
  18.                 for(var td=td_idx+1; td<=td_last;td++)
  19.                 {
  20.                     if ($(this).attr('checked') == true) 
  21.                     {
  22.                                 df[0].rows[tr_idx].cell[td_idx] = 1;//index[1] = Full Access
  23.                         if (td_idx==3) 
  24.                             {
  25.                                 df[0].rows[tr_idx].cell[td] = 1;
  26.                             }        
  27.                                 df[0].rows[tr_idx].cell[2] = 1;
  28.                         if (td_idx > 3)
  29.                             {
  30.                                 df[0].rows[tr_idx].cell[2] = 1;
  31.                             }                        
  32.                     }
  33.                     else 
  34.                     {            
  35.                                 df[0].rows[tr_idx].cell[td_idx] = 0;//index[0] = With Access
  36.                         if (td_idx==2) 
  37.                             {
  38.                                 df[0].rows[tr_idx].cell[td] = 0;
  39.                             }
  40.                         else if (td_idx==3) 
  41.                             {                            
  42.                                 df[0].rows[tr_idx].cell[td] = 0;                        
  43.                             }                            
  44.                         if (td_idx > 3)
  45.                             {
  46.                                 df[0].rows[tr_idx].cell[3] = 0;
  47.                             }
  48.                     }
  49.                 }
  50.                     $('#detFlex1').flexAddData(df[0]);
  51.                     $('.toolbar a[title=Edit Item]').trigger('click');
  52.                  });    
  53.         }
  54.     );
  55. }
Attached Files
File Type: txt javascript.txt (4.9 KB, 6 views)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,642
#2: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


do you have a site where I can check that? At first glance I don’t see a cause for such a delay, so I’d use FireBug to check that.
Newbie
 
Join Date: Oct 2009
Posts: 5
#3: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


Hi, Dormilich

Thanks for checking the codes. I am also using Firebug. No error is being displayed. I'm suggesting of redoing the javascript code but im still a newbie xD.

This is an open source web app.
http://www.comunionerp.com/web/sec_users/login

PS: if you are interested in contributing some codes then please add me in ym: <email_removed>

Thanks
-Dean
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,642
#4: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


Quote:

Originally Posted by kikz4life View Post

I am also using Firebug. No error is being displayed.

I don’t want to check the code for correctness, I want to see if I can find the line that takes so long using the breakpoints.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,642
#5: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


Quote:

Originally Posted by kikz4life View Post

This is an open source web app.
http://www.comunionerp.com/web/sec_users/login

the page responds reasonably well, maybe your connection is too slow? (despite I’m not sure, whether this is the page you’re talking about, since I didn’t find the ids and classes from the code)
Newbie
 
Join Date: Oct 2009
Posts: 5
#6: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


Expand|Select|Wrap|Line Numbers
  1. $(celDiv).click
  2.     (
  3.          function()
  4.         {
  5.             $('input',this).each(
  6.                  function(){
  7.  
  8.                     var tr_idx = $('#detFlex1 tbody tr').index($(this).parent().parent().parent());    
  9.                     var td_idx = $('#detFlex1 tbody tr:eq('+tr_idx+') td').index($(this).parent().parent());
  10.                     var td_last = 13;
  11.             ............
  12.                  });    
  13.         }
  14.     );
  15. }
i'm thinking that the problem is within this code. What do u think.?

Thanks again
-Dean
Newbie
 
Join Date: Oct 2009
Posts: 5
#7: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


Quote:

Originally Posted by Dormilich View Post

the page responds reasonably well, maybe your connection is too slow? (despite I’m not sure, whether this is the page you’re talking about, since I didn’t find the ids and classes from the code)

have u tried the site? the problem is not in the the login page. Its in the User Access Level located at the side nav in the main page under Administrator Module. http://www.comunionerp.com/web/sec_accesslevel
Newbie
 
Join Date: Oct 2009
Posts: 5
#8: Oct 6 '09

re: HELP: Slow response in checkbox using javascript and ajax


awts, i cant login. someone change the password of admin again.. X-(.

anyway i have attach a .bmp. this is how it looks like in the page(attached).
Attached Thumbnails
checkbox.jpg  
Reply


Similar JavaScript / Ajax / DHTML bytes