Reputation: 309
I have an ajax script which fetches results from a web-service and displays them in a div, however I would like them to be displayed in an input area / text field.
My main script:
<script type="text/javascript">
function get_CODES_Results() {
document.getElementById("results").innerHTML = "<img src=\'loading.gif\' />";
var url = document.location;
if (window.XMLHttpRequest) req = new XMLHttpRequest();
else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = processRequest;
//req.open("GET", url, true);
//req.send(null);
req.open("POST",url,true);
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
req.send("codes="+document.getElementById("codes").value);
function processRequest() {
if (req.readyState == 4) {
document.getElementById("results").innerHTML = req.responseText;
}
}
}
</script>
And here the area where it is being displayed:
<p>
<h3>Results:</h3>
<div id="results"></div>
</p>
My question:
How can I achieve that my result is displayed in an input/text-field?
Some advice would be highly appreciated - thank you, Patrick
Upvotes: 0
Views: 235
Reputation: 3956
Suppose this is your text field:
<input type="text" id="whatever" value="" />
Simply set the response to its value:
document.getElementById('whatever').value = req.responseText;
Upvotes: 2
Reputation: 33554
this?
document.getElementById("results").value = req.responseText;
<input id="results" type="text" />
Upvotes: 2
Reputation: 5847
Try with this:
document.getElementById("results").value = req.responseText;
And then you results should be an input:
<input type="text" id="results" />
Upvotes: 2