new to AJAX, need help for finishing touches
I'm creating a serial number validation script. It's working and test properly, with a few minor hiccups.
Here's the Javascript code.
<script type="text/javascript">
var SERIAL_QUERY_STRING = 'ServiceName=SerialValidation&serialNumber=';
function testSerial(query_str,disp_elem) {
var http_request = false;
alert("test again");
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
//alert(query_str);
http_request.onreadystatechange = function() { showValidation(http_request,disp_elem); };
http_request.open('POST', "/store/listener.cgi/oqo/oqoservices.p", true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
http_request.send(query_str);
}
function showValidation( http_request, target_element ) {
//alert('There was a problem');
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert( http_request.responseText );
} else {
alert('There was a problem with the request.');
}
}
}
function getSerial () {
SERIAL_QUERY_STRING = SERIAL_QUERY_STRING + document.rma_form.unit_sn.value;
testSerial (SERIAL_QUERY_STRING, '');
}
</script>
I'm calling the fuction in the form with an onblur event.
<input onblur="getSerial();" class="menu_input" maxlength="255" type="text" size="33" name="unit_sn" />
The problem I'm having is, when I enter a serial number in the text field, and it validates wrong and try to re-enter a valid serial number, the text field retains the previous value as well as the newly entered value. I'm thinking that the focus remains on the text field. How can I shift the focus off of it? I could be wrong, I've been looking at this all afternoon trying to figure it out.
Also, I've implemented a ton of "alerts" to keep track of what the script is doing, I've tried to delete and comment out all of them but I might have missed a few. Also, when the serial number returns true, I'd like to display some text in the form to the right or below the text field. something like "valid serial number!"
Thanks in advance! =)
-mon

