Connecting Tech Pros Worldwide Help | Site Map

speeding up response.

Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#1: Aug 11 '08
In an effort to make my apps run faster, I have started to embed a search feature into the html page with javaScript to call and execute an ajax routine. Everything works fine except for setting focus to the first (and only) input element.
Expand|Select|Wrap|Line Numbers
  1. //~~~~~ Display search box ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. function showPopSearch( ) {
  3.     if (  document.getElementById("popSearch").style.visibility == "hidden" ) {
  4.         document.getElementById("popSearch").style.backgroundColor = "#E4BF87";
  5.         document.getElementById("popSearch").style.borderStyle = "ridge";
  6.         document.getElementById("popSearch").style.borderWidth = "5px";
  7.         document.getElementById("popSearch").style.borderColor = "orange";
  8.         document.getElementById("popSearch").style.zIndex = "99";
  9.         document.getElementById("popSearch").style.visibility = "visible";
  10.         document.getElementById("popSearch").style.overflow = "hidden";
  11.  
  12. //to make this brief showGetSearch() is not shown here
  13.         showGetSearch( );
  14.  
  15. //I have to use this timeout or it will run right past the giveSeachFocus( )
  16.         var TimeoutID = setTimeout("giveSearchFocus()", 150);
  17.     }
  18. }
  19.  
  20. //~~~~~ Give Search element focus ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. function giveSearchFocus(){
  22.     document.getElementById("SEARCH").select();
  23.     document.getElementById("SEARCH").focus();
  24. }
  25.  
  26.  
The problem is sometimes, the cursor is there instantaneously other times it can take several seconds for it to appear. The users are annoyed that they cannot start typing right away. How can I resolve this issue and always have the cursor appear right away?
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#2: Aug 11 '08

re: speeding up response.


can you confirm that the field has NO focus or is the focus just 'invisible' ... so you could type instantly ... but just don't notice the focus? this problem seems to be common and i never saw a solution ... but you could 'workaround' it with setting a border around focused fields or a background-color ... so that the focus could be easily noticed ... the cursor alone seems to be a not quite good indicator ... but may be someone has a better solution?

kind regards
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#3: Aug 11 '08

re: speeding up response.


It is visible, you just cannot type in it until the cursor appears.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#4: Aug 11 '08

re: speeding up response.


then there are some synchronous requests like large js-libs, frames etc.? that might be loaded the same time?
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#5: Aug 11 '08

re: speeding up response.


when I try this

Expand|Select|Wrap|Line Numbers
  1.  
  2. document.getElementById("SEARCH").style.background-color = "yellow";
  3.  
I get this error.

invalid assignment left-hand side
[Break on this error] document.getElementById("SEARCH").style.background-color = "yellow";\n

But I was able to do this to verify that the cursor was red
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("SEARCH").select();
  2. document.getElementById("SEARCH").focus();
  3. document.getElementById("SEARCH").style.color = "red";
  4.  
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#6: Aug 11 '08

re: speeding up response.


it has to be:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("SEARCH").style.backgroundColor 
kind regards
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#7: Aug 15 '08

re: speeding up response.


Ok I got the back ground color established to check. I can now say that the cursor and color are both delayed.

I have also established that the problem occurs when switching from one type of search request to another. I have several places on each screen where a user can request (click on) a search i.e. they can click on the company Id or company name. The same number of parameters are sent to the search request in either case.

Expand|Select|Wrap|Line Numbers
  1. onmousedown="if (CheckForChange(this.form,'no')) {showPopSearch(event,'Client Id','10','8','client','by Id','id','no','client)};"
  2.  
  3. onmousedown="if (CheckForChange(this.form,'no')) {showPopSearch(event,'Client Name','60','50','client','by Name','Name','no','client)};"
  4.  
As you can see the calls are identical except for the parameters.

On the initial request the popup is instantaneous. But if the user then select a 2nd search request on a different link the delay will occur?

How can I track where the slowdown is occurring. I am using FireFox with Firebug, so I can see response when the page loads but not the execution time of the scripts after the page is loaded, at least I don't know how.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#8: Aug 16 '08

re: speeding up response.


typically there are just two simultanous http-requests allowed ... does the problem occur with two or just more requests? you could either abort the running requests or just don't check every field aqainst the backend through preloading some more data ...
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#9: Aug 18 '08

re: speeding up response.


There would always be only one request running at the time.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#10: Aug 19 '08

re: speeding up response.


?? how is this ensured ?? you just said that you could search something and simultanously search for another thing ... is it sure that any search is not started before an already started one has returned? does any errors occur in firebug during the requests or response-handlings?
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#11: Aug 28 '08

re: speeding up response.


Thank you for your kind reply. Sorry for the delayed response, I am not a full time employee so I do not read these posts everyday.

You ask how can I ensure that only one search occurs at the time. Well the search is initiated by the user by clicking on one of several buttons. They are not likely to click on a 2nd button before they have completed the first search. The action of clicking on a button brings up the dialogue box into which the user has to enter the requested search information i.e. enter clients name. Then they click another button on the dialogue box to start the search. This action brings a response to the search dialogue box or responds "no records found". Therefore it is unlikely that they would stop the action of the first search and start a second search.

Besides at this point I am the one testing why the response is slow. And I know that I am only calling on search at the time.

I think you have pointed me to an area to look at, that being what is happening in my code when I change search criteria. So I will continue my search in the code for the answer.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,129
#12: Aug 28 '08

re: speeding up response.


hmmmm ... with a popup it even shouldn't be a problem in case it is a window ... every window handles its own requests (as far as i know) ... when closing it the request should be aborted. so it may be that there is something 'strange' when constructing the request ... in case you find something and need help with it just post back here :)

kind regards
Reply


Similar JavaScript / Ajax / DHTML bytes