Autocomplete

This is a followup to http:Q_28483537.html. Same issue.

I will provide live link to responders.
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard KortsAuthor Commented:
OK, thanks.
0
Ray PaseurCommented:
Recommend you create a test-case that can be exposed without password protections.  When we want to ask technical questions the most useful concepts are to be found in the SSCCE.  It's nearly impossible to debug software when we cannot see the test data and the code.
0
leakim971PluritechnicianCommented:
replace :

function showHint(str) {
	gstr = str;

Open in new window


by :

var notYet = false;
function showHint(str) {
        if(notYet) return false;
        notYet = true;
	gstr = str;

Open in new window


and replace :
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			name_array=xmlhttp.responseText;

Open in new window


by:
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			notYet = false;
			name_array=xmlhttp.responseText;

Open in new window


finally replace :
<input type="text" size="50" onkeyup="showHint(this.value)" onChange="chk_blnk(this.value);">

Open in new window

by :
<input type="text" size="50" onkeyup="return showHint(this.value)" onChange="chk_blnk(this.value);" />

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

leakim971PluritechnicianCommented:
else do synchronous ajax call so replace :
if (document.getElementById("c").checked) {
		xmlhttp.open("GET","get_cname1.php?q="+qstr,true);
	}
	if (document.getElementById("a").checked) {
		xmlhttp.open("GET","get_addrn.php?q="+str,true);
	}
	if (document.getElementById("p").checked) {
		xmlhttp.open("GET","get_phonen.php?q="+str,true);
	}	
	if (document.getElementById("m").checked) {
		xmlhttp.open("GET","get_commentsn.php?q="+qstr,true);
	}
	if (document.getElementById("n").checked) {
		xmlhttp.open("GET","get_cnumbern.php?q="+str,true);
	}
	if (document.getElementById("w").checked) {
		xmlhttp.open("GET","get_wonumn.php?q="+str,true);
	}
	if (document.getElementById("e").checked) {
		xmlhttp.open("GET","get_emailn.php?q="+str,true);
	}

Open in new window

by :
if (document.getElementById("c").checked) {
		xmlhttp.open("GET","get_cname1.php?q="+qstr,false);
	}
	if (document.getElementById("a").checked) {
		xmlhttp.open("GET","get_addrn.php?q="+str,false);
	}
	if (document.getElementById("p").checked) {
		xmlhttp.open("GET","get_phonen.php?q="+str,false);
	}	
	if (document.getElementById("m").checked) {
		xmlhttp.open("GET","get_commentsn.php?q="+qstr,tfalse);
	}
	if (document.getElementById("n").checked) {
		xmlhttp.open("GET","get_cnumbern.php?q="+str,false);
	}
	if (document.getElementById("w").checked) {
		xmlhttp.open("GET","get_wonumn.php?q="+str,false);
	}
	if (document.getElementById("e").checked) {
		xmlhttp.open("GET","get_emailn.php?q="+str,false);
	}

Open in new window

0
leakim971PluritechnicianCommented:
what happen is when user type quickly or have a fast computer, connexion you have multiple ajax call whihc append the same result because each ajax call are inddepend of others aand not sequential, one after one
0
Richard KortsAuthor Commented:
To leakim971

I don't understand the first part. You say to put above Function showHint.

That seems illogical, that will only be executed ONCE when the page loads.

Is that the intention?

Every else makes sense; I never though about fast typist, I am slow.

Thanks!
0
leakim971PluritechnicianCommented:
The first code block any keypress until thé last Ajax  call is ended
0
Richard KortsAuthor Commented:
To leakim971

I don't understand what that means.

Thanks.
0
leakim971PluritechnicianCommented:
it will slow fast typist
0
Richard KortsAuthor Commented:
I understand that; what I DO NOT understand is where to put the JavaScript statement:

var notYet = false;

Thanks,

Rkorts
0
leakim971PluritechnicianCommented:
Just do a replace of the block, just like explained in my first answer
0
Richard KortsAuthor Commented:
To leakim971,

I applied the changes. Now it doesn't work at all. That is, type in three letters like "Mil" & nothing shows.

HTML attached.

Thanks,

rkorts
cust-wons.htm
0
leakim971PluritechnicianCommented:
move line 129 after line 235
your should use if,if else instead if,if, if lines 215 to 235
bad = "N";
	
tp = "c";
ac = "";	
wid = "";
wsch = "";
cid = 0;
cname = "";
pstr = "";
	
wrk = new Array();
var nw;
var gstr = "";

	function chk_vals() {
		if (ac == "a") {
			document.ts.action = "add_updt_cust.php";
			return true;
		}
		return true;
	}
	function chk_vals_cd() {
		type = get_radio_type();
		if (ac == "b") {
			dest = "asbuilts/" + cid + ".gif";
			window.open(dest,"asbuilt","width=800,height=1100,scrollbars=yes,menubar=yes");
			ac = "";
			return false;
		}
		if (ac == "d") {
			jj = confirm("Confirm deletion of customer " + cname + "?");
			if (! jj) {
				return false;
			} else {
				document.cd.action = "delete_cust.php?cid=" + cid + "&pstr=" + gstr + "&type=" + type;
				return true;
			}
		}	
		if (ac == "c") {
			document.cd.action = "add_updt_cust.php?cid=" + cid + "&pstr=" + gstr + "&type=" + type;
			return true;
		} else {
			document.cd.action = "base_cust_updt.php?cid=" + cid + "&pstr=" + gstr + "&type=" + type;
			return true;
		}	
	}	
	function chk_vals_wo() {
		type = get_radio_type();
		if(ac == "aw") {
			document.wo.action = "add_updt_wo.php?cid=" + cid + "&type=" + type + "&pstr=" + gstr + "&mode=a";
			return true;
		}
		if (ac == "u") {
			document.wo.action = "add_updt_wo.php?wo=" + wid + "&cid=" + cid + "&type=" + type + "&pstr=" + gstr;
			return true;
		}
		if (ac == "e") {
			window.open("email_wo.php?wid=" + wid, "email", "height=600,width=700,scrollbars=yes,menubar=yes");
			return false;
		}
		if (ac == "p") {
			window.open("print_wo.php?wo=" + wid, "print", "height=1500,width=1000,scrollbars=yes,menubar=yes");
			return false;
		}	
	}	
function repos_list() {
	ky = document.ts.ss.value;
	ky = ky.toUpperCase();
	lx = ky.length;
	m=document.ts.cnms.options.length
	for (i = 0; i < m; i++) {	
		v = document.ts.cnms.options[i].value;
		v = v.toUpperCase();
		jj = v.indexOf(ky);
		if (jj == -1) {
			document.ts.cnms.options[i].style.display = "none";
		}else{
			document.ts.cnms.options[i].style.display = "block";
		}
	}	
}
function re_do(x) {
	document.ts.action = "cust_won.php?type=" + x;
	document.ts.submit();
}
function go_cust() {
	val = encodeURIComponent(document.ts.cnms.value);
	type = get_radio_type();
	document.ts.action = "cust_wons.php?pstr=" + gstr + "&cid=" + val + "&type=" + type;
	document.ts.submit();
}
function get_radio_type() {
	if (document.ts.st[0].checked) {
		tp = "c";
	}
	if (document.ts.st[1].checked) {
		tp = "a";
	}
	if (document.ts.st[2].checked) {
		tp = "p";
	}
	if (document.ts.st[3].checked) {
		tp = "m";
	}
	if (document.ts.st[4].checked) {
		tp = "e";
	}
	if (document.ts.st[5].checked) {
		tp = "n";
	}
	if (document.ts.st[6].checked) {
		tp = "w";
	}
	return tp;
}	
function chk_ws() {
	if (wsch != "") {
		alert("No Work Orders found for " + wsch + ".");
	}
	if (cid != 0) {
		showHint(pstr);
		
	}	
		
}
var notYet = false;
function showHint(str) {
    if(notYet) return false;
    notYet = true;
	gstr = str;
	ml = 3;
	if (document.getElementById("n").checked) {
		ml = 5;
	}
	if (document.getElementById("w").checked) {
		ml = 6;
	}	
	if (str.length<ml) {
		document.getElementById("cnms").options.length = 0;
		return;
	}
	document.getElementById("cnms").options.length = 0;
	var xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			notYet = false;
			name_array=xmlhttp.responseText;
			if (name_array != "") {
				cnames = name_array.split(",");
				nr = cnames.length;
				cname = new Array();
				k = 0;
				for (i = 0; i < nr; i++) {
					if (i == 0) {
						cname[0] = cnames[0];
						k++;
					} else {
						dupe = false;
						for (j = 0; j < k; j++) {
							if (cnames[i] == cname[j]) {
								dupe = true;
								break;
							}	
						}
						if (! dupe) {
							cname[k] = cnames[i];
							k++;
						}
					}
				}		
				var x = document.getElementById("cnms");
				for (i = 0; i < k; i++) {
					tname = cname[i];
					bgc = get_bgcolor(tname);
					ln = tname.length;
					bgcl = "";
					if (bgc != "") {
						tname = tname.substr(3,ln-3);
						if (bgc == 'r') {
							bgcl = "background-color:red;";
						}
						if (bgc == 'g') {
							bgcl = "background-color:green;";
						}
						if (bgc == 'y') {
							bgcl = "background-color:yellow;";
						}
						if (bgc == 'p') {
							bgcl = "background-color:#800080;";
						}
					}	
					cnum = tname.substr(0,5);
					ln = tname.length;
					tname = tname.substr(5,ln-5);
					var opt = document.createElement('option');
					opt.text = tname.replace("&#39;", "'");
					opt.value = cnum;
					if (cid != 0) {
						if (cid == cnum) {
							opt.selected = true;
							document.getElementById("cnms").selectedIndex = i;
						}
					}		
					if(bgcl != "") {
							opt.setAttribute('style', bgcl);
					}
					x.appendChild(opt);	
				}	
			}
		}

	}
	var timestamp = new Date();
	qstr = encodeURIComponent(str);
	if (document.getElementById("c").checked) {
		xmlhttp.open("GET","get_cname1.php?q="+qstr,true);
	}
	if (document.getElementById("a").checked) {
		xmlhttp.open("GET","get_addrn.php?q="+str,true);
	}
	if (document.getElementById("p").checked) {
		xmlhttp.open("GET","get_phonen.php?q="+str,true);
	}	
	if (document.getElementById("m").checked) {
		xmlhttp.open("GET","get_commentsn.php?q="+qstr,true);
	}
	if (document.getElementById("n").checked) {
		xmlhttp.open("GET","get_cnumbern.php?q="+str,true);
	}
	if (document.getElementById("w").checked) {
		xmlhttp.open("GET","get_wonumn.php?q="+str,true);
	}
	if (document.getElementById("e").checked) {
		xmlhttp.open("GET","get_emailn.php?q="+str,true);
	}	
	xmlhttp.send();
}
function chk_blnk(x) {
	if (x.length < 3) {
		document.getElementById("cnms").options.length = 0;
	}
}
function get_bgcolor(x) {
	c = "";
	if (x.substr(0,1) == "/" && x.substr(2,1) == "/") {
		c = x.substr(1,1);
	}
	return c;
}

Open in new window

0
Richard KortsAuthor Commented:
To leakim971,

Still fails. Here is code after move you suggested:

var notYet = false;
function showHint(str) {
    if(notYet) return false;
      gstr = str;
      ml = 3;
      if (document.getElementById("n").checked) {
            ml = 5;
      }
      if (document.getElementById("w").checked) {
            ml = 6;
      }
      notYet = true;
      if (str.length<ml) {
            document.getElementById("cnms").options.length = 0;
            return;
      }
0
leakim971PluritechnicianCommented:
no, the lines I'm talking about is from the code snippet I posted in my previous answer not in your code
because as you make lot of test and sometimes not setting back notYet to false, we need to set it just before the ajax call, xhr.send()
0
Richard KortsAuthor Commented:
OK, I did that & it seems to work.

I will ask the customer to test it.

Thanks!
0
leakim971PluritechnicianCommented:
'welcome
0
Richard KortsAuthor Commented:
It may be a day or two before I know; the customer is in their "busy" season & doesn't have much time for testing the "new" system right now.
0
Richard KortsAuthor Commented:
To leakim971,

The customer reported he is still getting duplicates on his Macbook, using Chrome.

See attached.

I am awaiting response from the admin person who uses the system most on a Win 7 PC with Chrome.

Thanks
Screen-Shot-2014-09-04-at-1.36.06-PM.jpg
0
leakim971PluritechnicianCommented:
be sure they clear their cache...
0
Richard KortsAuthor Commented:
To leakim971,

He did it again, cache cleared. Same result.

So I have to believe that your solution did not work.

Thanks
0
leakim971PluritechnicianCommented:
try the second solution
0
leakim971PluritechnicianCommented:
ID: 40299907
0
Richard KortsAuthor Commented:
To leakim971

It kind of works for me but if you type to quickly it will miss some letters.

They are wanting to type in the WHOLE name most of the time, so that's what I did to to test it.

Does the other mode slow it down?
0
Richard KortsAuthor Commented:
To all,

I seem to have solved the problem via trial & error.

I realized that the database table that contained the customer names (about 12,500 presently) was not index on the names so I introduced an index on the last name, first name.

This action actually seems to make the process too fast; results from 3 keys were NOT replaced with results from 5 - 6 key strokes.

So I put a delay in, like this:

if (document.getElementById("c").checked) {
            setTimeout(xmlhttp.open("GET","get_cname1.php?q="+qstr,true), 200);
      }
I had first tried it with 100 ms, bad results remained. I set it to 200MS, customer says it now works fine. Of course it may not work fine forever, but for now, seems OK.

Thanks for your efforts.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsAuthor Commented:
As described in the text given.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.