Hi, this is a rough guide to adding AJAX field validation.
firstly, a new file, uploaded to the main indexU folder, copy this, and save it as "post_url.php"
Load up add form.Code:<? include ("application.php"); $url = $_REQUEST["url"]; $query = " SELECT url FROM idx_link WHERE url = '$url' LIMIT 0 , 30 "; $result = $dbConn->FetchArray($query); $num = count($result); if($num > 0){ //uurl already exists echo "Sorry your site is already Added."; }else{ echo "Thanks, the URL seems fine!"; } ?>
at the top add this :
almost done, just change this on the add_form.html :Code:<script type="text/javascript"> var http = false; if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); } function validate2(url) { http.abort(); http.open("GET", "post_url.php?url=" + url, true); http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById('message').innerHTML = http.responseText; } } http.send(null); } </script>
Try it out!! to make it really cool, instead of the message load a little green tick or red cross image, use this template to validate phone numbers, usernames - allsorts of thigns on the form before its even submittedCode:<input type="text" size="40" name="url" value="<%$url%>" onBlur="validate2(this.value)" class="textbg"> <div id="message"></div>
Im using it ont he admin panel when i add sites - i can see straight away if its a duplicate.




