I know AJAX is the answer but I don't know how

Hi, I have this ID text entry in one of may web page. Whenever the user inputted a correct ID it will return the following value; full name and position. The two values mentioned will be shown into a textbox also at the same page. How am I be able to do that, I am thinking of AJAX, but I don’t know how to do it. Please help me.

You can use the code above posted by jim9, but I would suggest jQuery, as it will be a lot easier to read and integrate into your site. It would also be a little less code.

function getXMLHTTP() { //fuction to return the xml http object
    var xmlhttp = false;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e1) {
                xmlhttp = false;
            }
        }
    }

    return xmlhttp;
}
function getowner(flag,page,sch) {
    displayPopupDiv();
    if (flag == '0') {
        var dsch = prompt('search string', '');
        page = 1;
        //displayPopupDiv();
        var strURL = "owner2.aspx?dsch=" + dsch + "&flag=" + flag + "&page=" + page;
    }
    if (flag == 1) {
        var page = 1;
        var dsch = document.getElementById('tdivsearch').value;
        var strURL = "owner2.aspx?dsch=" + dsch + "&flag=" + flag + "&page=" + page;
    }
    if (flag == 2 || flag == 3) {
        //var page = 1;
        page = page
        var dsch = sch;
        var strURL = "owner2.aspx?dsch=" + dsch + "&flag=" + flag + "&page=" + page;
    }
    
    var req = getXMLHTTP();

    if (req) {

        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if "OK"
                if (req.status == 200) {
                    document.getElementById('ownerIDdiv').innerHTML = req.responseText;
                } else {
                    alert("There was a problem while using XMLHTTP:\
" + req.statusText);
                }
            }
        }
        req.open("GET", strURL, true);
        req.send(null);
    }
}

Is how I use ajax with asp.net. Make sure your results are in a div.
This is a basic get.
Code your results first as if no ajax will be used, then add ajax to call the code.
All gets work like this. This is regular ajax and javascript, I don’t use jquery.
I have not shown validation or security, add that as needed.

Hi

yes, my apologies. Been very busy lately, don’t have time to type code here. I will soon though.

In the meantime, check this out:
http://api.jquery.com/category/ajax/

Everything should be there that you need

Thanks jim9

You can use the code above posted by jim9, but I would suggest jQuery, as it will be a lot easier to read and integrate into your site. It would also be a little less code.

I gave sample code, why can’t you post some sample jquery code to help fellow sitepoint forum viewers? It’s just too easy to say use jquery. How, what would example code look like? I may even want to try to replace my ajax with jquery.

a little less code

How is it less code when you have the code to write to interface with jquery plus the jquery library included? Just wondering?

Can I presume that the return values are coming from the database?

SitePoint has articles on AJAX. Have you read any of them?

Cheers,
D.