If I read that correctly there's always a:
Code:
xmlObj.getElementsByTagName('result').item(0).firstChild.data;
If a dupe was found, it's the "Sorry . . ." message. If not it's just a dot (.).
So you could test the length:
Code:
function statechange_username() {
if (http.readyState == 4) {
var xmlObj = http.responseXML;
var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
html = html.length > 1? '<img src="crossicon.gif" alt="">' + html : '';
document.getElementById('user_error').innerHTML = html;
}
}
You could do that. An alternative would be to put the image tag into the xml document as it's being created. I'm uncertain of the proper syntax for that, but believe it can be done. There might be cross browser issues around that though. Inserting it where I've just shown, in the javascript part of the operation, would be the safest.
Another approach would be to have the PHP code create an HTML fragment instead of an xml document, and have the statechange function use the responseText rather than the responseXML. Then it would be relatively easy to create cross browser HTML with the PHP script.
PHP Code:
<?php
$count = mysql_num_rows(mysql_query("SELECT * FROM usertable WHERE `username`='".$username."'"));
header('Content-type: text/html; charset=utf-8');
header('Pragma: no-cache');
echo '<span>';
if($count > 0) {
echo '<img src="crossico.gif" alt="">Sorry! This Login-ID already exists.';
}
echo '</span>';
?>
Code:
function statechange_username() {
if (http.readyState == 4) {
document.getElementById('user_error').innerHTML = http.responseText;
}
}
Bookmarks