window.status = "Searching for vehicle '"+vin+"' in Waybill...";
var win = window;
var req = createXMLHttpRequest();
req.open("GET", "wbVinLookupData.jsp?VIN="+vin, false, null, null);
req.onreadystatechange = function () {
if(req.readyState == 4) {
alert(req.responseText);
var vehicles = [];
try {
vehicles = eval('('+req.responseText+')').vehicles;
} catch (err) {
vehicles = [];
}
Up to that point it works OK in IE 7 as well. Next I act differently
based on the number of returned vehicles:
if (vehicles.length==0) {
alert("VIN '"+vin+"' not found in Waybill!");
} else if (vehicles.length==1) {
var vehicle = vehicles[0];
setVinInfo(win,
vehicle.VIN,
vehicle.customer,
vehicle.location);
win.document.getElementById(
"wbModelInfo").innerHTML = vehicle.modelInfo;
} else {
win.open("chooseVin.jsp?VIN="+vin,
"chooseVin",
"height=300,width=400,scrollbars");
}
}
With IE7, I always get the first ("VIN not found") case, even if I
can see that the returned array has one or several vehicle records.
Does anyone have an idea of the solution to either of these problems?
--
David Lee Lambert
Software Developer, Precision Motor Transport Group, LLC
work phone 517-349-3011 x223
cell phone 586-873-8813
e-mail dlam...@bmtcarhaul.com
Is this form all on the same page? If so, I don't think you need ajax
to do this.
You could use the input fields onblur event to call a function that
populated another input field in the form. The onblur function
executes when the control loses focus.
I'm trying to build a mostly single-page application; but the first
field needs to be validated against a database that currently has
almost 535 thousand records, and continues to grow. I can't pack that
much data in a hidden field, for instance, and still have the page
load in a reasonable amount of time.
I could abandon the goal of building a Web 2.0-ish application and put
the first field on a separate page; but there are other fields on the
form that should also change some available option sets or simply be
validated as soon as possible. Another concern is that it would be
"clunky" and hard-to-understand.
The code I posted is called from the onblur handler of an input field.
--
David Lee Lambert
Software Developer, Precision Motor Transport Group, LLC
work phone 517-349-3011 x223
cell phone 586-873-8813
e-mail dlam...@bmtcarhaul.com