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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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