0

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!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by brixton
0

>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.

0

>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

0

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);
}

Edited by brixton: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.