how to display textbox entered value and with related values intextare using javascr

V

venkat reddy

Hi friends,

i have xnl file like

<DATAPACKET >
<data1>
<R_ID>101</R_ID>
<R_PRE>38</R_PRE>
<R_PRE2>39</R_PRE2>
<R_TEMP>8.35</R_TEMP>
<R_TENP2>0.64</R_TENP2>
</data1>
<data1>
<R_ID>102</R_ID>
<R_PRE>36</R_PRE>
<R_PRE2>37</R_PRE2>
<R_TEMP>7.23</R_TEMP>
<R_TENP2>1.21</R_TENP2>
</data1>
<data1>
<R_ID>103</R_ID>
<R_PRE>34</R_PRE>
<R_PRE2>36</R_PRE2>
<R_TEMP>7.21</R_TEMP>
<R_TENP2>1.95</R_TENP2>
</data1>
<data1>
<R_ID>104</R_ID>
<R_PRE>32</R_PRE>
<R_PRE2>35</R_PRE2>
<R_TEMP>6.25</R_TEMP>
<R_TENP2>2.30</R_TENP2>
</data1>
<data1>
<DATAPACKET >

then i have textbox...when i type 101 its go and get all data in the
row in text area like

101
32
6025
2.30

please give me any idea how to do this

i m try this
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "Refrigerater.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
x = xmlDoc.getElementsByTagName("ROWDATA");

//x = xmlDoc.getElementsByTagName("data1");

function displayInfo(selBox) {
x = xmlDoc.getElementsByTagName("ROWDATA");
var col = (selBox.options[selBox.selectedIndex].text);
document.getElementById("show").innerHTML = "&nbsp;" + col;
}

Please resolve my problem

Thanks
Venkat.S
 
E

Elegie

On 08/07/2011 16:51, venkat reddy wrote :

Hi,
<DATAPACKET>
<data1>
<R_ID>101</R_ID>
<R_PRE>38</R_PRE>
<R_PRE2>39</R_PRE2>
<R_TEMP>8.35</R_TEMP>
<R_TENP2>0.64</R_TENP2>
</data1>
then i have textbox...when i type 101 its go and get all data in the
row in text area

I see that you want to use XmlHttpRequest (XHR) to do so. I am not
well-versed in this technology, so I gave it a try, for fun. I have used
Jim Ley's excellent code located at <URL:
http://jibbering.com/2002/4/httprequest.html>.

The script comes in two parts. "xhr.js" provides an encapsulation for
XHR requests, and "test-data.html" illustrates how to grab the data from
a XML file having the structure you have described. Note that the design
is straightforward, so would need a bit of refactoring to meet
production-quality standards.

-----------------------------------------------------------
xhr.js
-----------------------------------------------------------
var XHR = (function() {
var cache = {};
var getXHRObject = (function() {
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!="undefined") {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
return (function() {
return xmlhttp;
});
})();

return ({
canRun : (function() {return !!getXHRObject() ;}),
read : (function(file, callback){
if (cache[file]) {
callback(cache[file]);
} else {
var XHRObj = getXHRObject();
XHRObj.open("GET", file, true);
XHRObj.onreadystatechange = (function() {
if (XHRObj.readyState==4) {
cache[file] = XHRObj.responseXML;
callback(cache[file]);
}
});
XHRObj.send(null);
}
})
});
})();



-----------------------------------------------------------
test-data.html

Adjust as needed:
- the script path
- the xml file path
-----------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title>Test XHR GetData</title>
<meta charset="UTF-8">
<script type="text/javascript"
src="resources/scripts/0_0_1/xhr.js"></script>
<script type="text/javascript">
window.onload = (function (evt) {
if (XHR.canRun()) {
document.forms[0].onsubmit = (function (evt) {
// Process the XML file
// You could use other events to trigger the processing
var data = XHR.read(
"http://localhost:8080/ThotFaces/data.xml",
(function (xml) {
var searchedRow = document.forms[0].elements["R_ID"].value;
var result = [];
var rows = xml.documentElement.getElementsByTagName("R_ID");
for (var ii=0; ii<rows.length; ii++){
if(getText(rows[ii]).toLowerCase() ==
searchedRow.toLowerCase()) {
var parent = rows[ii].parentNode;
for(var j=0; j<parent.childNodes.length; j++) {
var child = parent.childNodes[j];
if (child.nodeType==1) {
result.push(getText(child));
}
}
break;
}
}
document.forms[0].elements["result"].value =
result.length == 0 ? "No match." : result.join("\n");
})
);

// Deactivate the fallback mechanism, since we can use XHR
return false;
});
}

function getText(node) {
if(node.nodeType==3) {
return node.nodeValue;
} else if(node.nodeType==1) {
var children=node.childNodes;
var text="";
for(var ii=0; ii<children.length; ii++) {
text += getText(children[ii]);
}
return text;
}
}
});
</script>
</head>
<body>
<form action="fallback.foo">
<input type="text" name="R_ID">
<input type="submit">
<br>
<textarea name="result" rows="10" cols="10"></textarea>
</form>
</body>
</html>


HTH,
Elegie.
 

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top