salam...nak tanya sket kat otai2 kat sini...mintak tlg tgkkan apa yg tak kena dgn coding ni...
form.php
ajax.php
prob yg aku hadapi skrg adalah aku nak displaykan image bersama2 dgn statement username exists atau tak..kalau just statement je..coding ni berfungsi dgn baik..tapi bila aku letak img..dia kuar undefined...
apa yg aku buat salah..n apa yg perlu aku tukar...mintak tolong kat otai2 kat sini.....
thanks
form.php
- Code:
<script type="text/javascript">
function toggle_username(userid) {
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
handle = document.getElementById(userid);
var url = 'ajax.php?';
if(handle.value.length > 0) {
var fullurl = url + 'do=check_username_exists&username=' + encodeURIComponent(handle.value);
http.open("GET", fullurl, true);
http.send(null);
http.onreadystatechange = statechange_username;
}else{
document.getElementById('username_exists').innerHTML = '';
}
}
function statechange_username() {
if (http.readyState == 4) {
var xmlObj = http.responseXML;
var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
document.getElementById('username_exists').innerHTML = html;
}
}
</script>
<input id="username" type="text" name="username" onchange="toggle_username('username')" /><br />
<div id="username_exists" style="font-size: 11px;font-weight: bold;color:#FF3300"> </div>
ajax.php
- Code:
<?php
mysql_connect ('localhost', 'USERNAME', 'PASSWORD');
mysql_select_db('DATABASE');
$do = $_GET['do'];
switch($do) {
case 'check_username_exists':
if(get_magic_quotes_gpc()) {
$username = $_GET['username'];
}else{
$username = addslashes($_GET['username']);
}
$count = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `username`='".$username."'"));
header('Content-Type: text/xml');
header('Pragma: no-cache');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<result>';
if($count > 0) {
//echo "<img src'cross.png'></img> That username already exists, please select another one.";
echo 'That username already exists, please select another one.';
}else{
echo 'That username is available.';
}
echo '</result>';
break;
default:
echo 'Error, invalid action';
break;
}
?>
prob yg aku hadapi skrg adalah aku nak displaykan image bersama2 dgn statement username exists atau tak..kalau just statement je..coding ni berfungsi dgn baik..tapi bila aku letak img..dia kuar undefined...
apa yg aku buat salah..n apa yg perlu aku tukar...mintak tolong kat otai2 kat sini.....
thanks