Jump to content

Is this even possable?


steviez

Recommended Posts

Hi,

 

On my site i have a pm system where users can contact each other. What i want to do is this:

 

When a user types in the name of the person they want to pm i want it to bring up their profile picture at the side of the form. If this is possable can anyone show me an example?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/117427-is-this-even-possable/
Share on other sites

can't give you an exact example but, all you have to do is when the user leaves the text box where they enter the username (i say leave as you can assume they're done typing) submit an AJAX request that queries the database for that user and upon finding it, update the display where you want to show the image....or show that that user is not found. 

 

what is the extent of you AJAX knowledge?

 

-grant

Maybe this will help you?

 

var url = "checknick.php?name=";

function checkName() { 
  document.getElementById('ajax_answer').innerHTML = "...loading, please wait..."; 
  var name = document.getElementById("nickname").value; 
  http.open("GET", url + escape(name), true); 
  http.onreadystatechange = handleHttpResponse; 
  http.send(null); 
} 

function handleHttpResponse() { 
  if (http.readyState == 4) { 
    results = http.responseText; 
    var name = document.getElementById("nickname").value;
    document.getElementById('ajax_answer').innerHTML = results; 
  }
} 

function createRequest() {
  try {
    return new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
         alert("Error initializing XMLHttpRequest!");
      }
    }
  }
}

var http = createRequest();

 

HTML:

 

Nickname: <input name="name" id="nickname" type="text" onblur="checkName();" /> <span id="ajax_answer"><br><br>

 

Explanation:

When you're finished entering user's nickname in the field, it'll call the script /checknick.php?name=(users nickname), and fetch the data from it, then display in SPAN "ajax_answer".

All you need to do now is to create database-checking checknick.php.

 

Hope this helps!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.