![]() |
|
|
|
|
1
16th November 04:45
External User
Posts: 1
|
It's possible, but it's still dependant on client-side JavaScript being enabled,
and it requires more work on the server. var serverCallBack = new Image(); serverCallBack.onload = callBackResponse; serverCallBack.onerror = callBackNoResponse; function callBackResponse() { if (this) { switch (this.width) { case 1: // do something break; case 2: // do something else break; // etc } } } function callBackNoResponse() { alert('Could not validate your input.'); } Then in your HTML, do something like: <input type="text" onchange="serverCallBack.src='yourValidator.cgi?da ta=' + this.value;" /> Now on the server, "yourValidator.cgi" will have to build (or read) and return content to the browser of Content-type: image/gif (or image/jpeg) with specific widths for each "response code" you want. In other words, a gif of width 1 would be for correct input, width 2 would be for input that's blank, width 3 would be for input that contains incorrect characters, etc. By the way, this is still asynchronous, if the user managed to trigger the onchange event in a second input while the server was still dealing with the first, it would cause a second asynchronous retrieval of "yourValidator.cgi". This could cause the onload events for serverCallBack to fire out of order (or only once for two retrievals). There are ways to avoid that problem as well by having a "pool" of serverCallBack objects and cycle through them, each with it's own onload event. If you had say, 10 of them, it's highly unlikely that a human could cause retrievals fast enough to cause the first one to be used again before it returned some sort of result. You've already said that you wanted a more cross-browser solution (ie - one that didn't use the XML HTTP Request object), so I'm assuming this is for the Internet? If so, as I've already said, the above functionality would only work if the user has client-side JavaScript enabled. Ultimately it might be better to just POST the form and have the server validate everything at once. -- | Grant Wagner <gwagner@agricoreunited.com> * Client-side Javascript and Netscape 4 DOM Reference available at: * http://devedge.netscape.com/library/...ce/frames.html * Internet Explorer DOM Reference available at: * http://msdn.microsoft.com/workshop/a...ence_entry.asp * Netscape 6/7 DOM Reference available at: * http://www.mozilla.org/docs/dom/domref/ * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla * http://www.mozilla.org/docs/web-deve...upgrade_2.html |
|
|
|