Hi,

I want to validate the user id that was entered in a textbox (similar to while registering to a site, we come across something like "this username already existed please choose different")

without refreshing the page (or i can say in textbox onchange event)

can someone guide me how to achieve this!

>I want to validate the user id that was entered in a textbox.

1. Use escaped string.
2. Use Parametrized query.

>without refreshing the page

AJAX - asynchronous JavaScript and XML.

>I want to validate the user id that was entered in a textbox.

1. Use escaped string.
2. Use Parametrized query.

>without refreshing the page

AJAX - asynchronous JavaScript and XML.

thank you adatapost!

But i am a newbbie in PHP, i know something about AJAX,
please kindly can u give simple example on this topic or atleast any link for this

thank you adatapost!

But i am a newbbie in PHP, i know something about AJAX,
please kindly can u give simple example on this topic or atleast any link for this

Here's an example of mine, not sure if it's "optimal" but it works.

sendMail() is called when form is submitted.

getHTTPObject() takes browser type into account and returns an HTTP object.

The PHP file contains, among other things (like validation of the data the user is submitting):

$retArray = array('success' => false, 'message' => "");
echo json_encode($retArray);
exit;

And this is the JavaScript:

function getHTTPObject(){
	if (window.ActiveXObject) 
      return new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) 
      return new XMLHttpRequest();
    else {
      alert("Your browser does not support AJAX.");
      return null;
    }
}

function sendComplete(text){
   var myObject = JSON.parse(text);
   document.getElementById('message_holder').innerHTML = myObject.message;
   if(myObject.success == false){
       document.getElementById('message_holder').style.color = "#BF0034";
   }
   if(myObject.success == true){
       document.getElementById('message_holder').style.color = "#ABCE5E";
       var inputs = document.getElementById('ContactForm').getElementsByTagName('INPUT');
       for(var i = 0; i < inputs.length; i++){
            inputs[i].value = "";
       }
       var textarea = document.getElementById('ContactForm').getElementsByTagName('TEXTAREA');
       textarea[0].value= "";
   }
}

function sendMail(){
    var httpObject= getHTTPObject();
    var name = document.ContactForm.name.value;
    var email = document.ContactForm.email.value;
    var phone = document.ContactForm.phone.value;
    var message = document.ContactForm.message.value;
    httpObject.open("GET", 'includes/ajax/send_message_mail.php?name='+name+'&email='+email+'&phone='+phone+'&message='+message+'&mailto=<?php echo $schoolInfo["email"];?>', true);
    httpObject.onreadystatechange = function(){
				if(httpObject.readyState == 4){
                                      sendComplete(httpObject.responseText);
				}
			}
			httpObject.send(null);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.