steviez Posted July 30, 2008 Share Posted July 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted July 31, 2008 Share Posted July 31, 2008 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 Quote Link to comment Share on other sites More sharing options...
steviez Posted July 31, 2008 Author Share Posted July 31, 2008 Hi, I have no knowlage at all, i would not even know where to start Thanks Quote Link to comment Share on other sites More sharing options...
Uzm Posted July 31, 2008 Share Posted July 31, 2008 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! Quote Link to comment Share on other sites More sharing options...
steviez Posted July 31, 2008 Author Share Posted July 31, 2008 perfect, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.