1: <script language="javascript">
2:
3: // used for displaying the "loading..." message
4: var loadingDIV = null;
5:
6: // This will hold reference to UserName control
7: var ctlUser = null;
8:
9: // This will hold reference to MAC Address control
10: var ctlMAC = null;
11:
12: // This will hold reference to Machine Name control
13: var ctlMachine = null;
14:
15: function f()
16: {
17: // Create a new XHR request (this will work only with browsers with native XHR support)
18: // for other browsers like IE6 or lower, you would need to change it to create XMLHttpRequest ActiveX object
19: var mygetrequest = new XMLHttpRequest();
20:
21: // Here is where we do our work, once data is received back
22: mygetrequest.onreadystatechange = function()
23: {
24: // Check readyState of the request
25: if (mygetrequest.readyState == 4)
26: {
27: // Check if we have the proper request status
28: if (mygetrequest.status == 200)
29: {
30: // get the mData from the request. This data comes as "Username|MAC|MachineName" string
31: // separated using a "|" (pipe) sign
32: var mData = mygetrequest.responseText;
33:
34: // split the data to get the string array
35: ar = mData.split("|");
36:
37: // MAC address is the 2nd element in the array, assign value to the MAC textbox
38: ctlMAC.value = ar[1];
39:
40: // Machine name is 3rd element in the array, assign value to Machine name textbox
41: ctlMachine.value = ar[2];
42:
43: // hide the "loading..." message as we have loaded the data properly
44: loadingDIV.style.display="none";
45: }
46: else
47: {
48: alert("An error has occured making the request")
49: }
50: }
51: }
52:
53: // Show the "loading..." DIV to show that we are fetching the data
54: loadingDIV.style.display="inline";
55:
56: // Send the actual request to our ASPX page which will read the XML file and give us data back
57: mygetrequest.open("GET", "/_layouts/Users/Default.aspx?u=" + ctlUser.value, true)
58: mygetrequest.send(null)
59: }
60:
61: // Fetch all the elements of tag as INPUT (we just need textbox references)
62: var ele = document.getElementsByTagName("input");
63:
64: // Loop through all the INPUT elements
65: for (a = 0; a < ele.length; a++)
66: {
67: try
68: {
69: ix = ele[a];
70:
71: // We need only the TEXT type INPUT elements
72: if (ix.type == "text")
73: {
74:
75: // SharePoint adds a TITLE attribute to each textbox which is exactly same as its Field Name
76: // Check if we found "USERNAME" field here
77: if (ix.attributes.getNamedItem("title").value.toLowerCase() == "username")
78: {
79: // Set the UserName control object reference
80: ctlUser = ix;
81:
82: // Set the onBlur event handler to point to function "f()" which will do the actual work
83: ctlUser.onblur = f;
84:
85: // Now create a new SPAN element which contains the "loading..." message
86: // and take its reference in "loadingDIV" and inset it after the UserName textbox
87: var xx = document.createElement("span");
88: xx.innerHTML = "loading...";
89: xx.id="loadingBlock";
90: xx.style.display = "none";
91: loadingDIV = xx;
92: ctlUser.insertAdjacentElement("afterEnd", xx);
93: }
94:
95: // If this TEXT type INPUT element is MAC address, take its reference
96: if (ix.attributes.getNamedItem("title").value.toLowerCase() == "mac")
97: {
98: ctlMAC = ix;
99: }
100:
101:
102: // If this TEXT type INPUT element is Machine name, take its reference
103: if (ix.attributes.getNamedItem("title").value.toLowerCase() == "machine")
104: {
105: ctlMachine = ix;
106: }
107: }
108: }
109: catch (ex)
110: {
111: //Right now we are not doing anything if any error occurs
112: }
113: }
114: </script>