获取在表单/文本字段中显示的结果
Get result displayed in form / textfield
我有一个ajax脚本,它从web服务获取结果并在div中显示,但我希望它们显示在输入区域/文本字段中。
我的主要脚本:
<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>
这里是它显示的区域:
<p>
<h3>Results:</h3>
<div id="results"></div>
</p>
我的问题:
如何实现我的结果显示在输入/文本字段中?
非常感谢您的建议-谢谢您,Patrick
试试这个:
document.getElementById("results").value = req.responseText;
然后你的结果应该是一个输入:
<input type="text" id="results" />
这个?
document.getElementById("results").value = req.responseText;
<input id="results" type="text" />
假设这是您的文本字段:
<input type="text" id="whatever" value="" />
只需将响应设置为其值:
document.getElementById('whatever').value = req.responseText;
相关文章:
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- JavaScript循环无法正确计算/显示结果
- 将循环中的两个文本框相乘,并在第三个文本框上显示结果
- BMI计算器以Javascript显示结果
- 在表中显示结果
- onchange选择get value并执行查询,然后在同一页面上显示结果
- 搜索XML文件并使用javascript显示结果
- Moment.js不显示结果
- 使用jQuery延迟表单输入,并在延迟后在同一页面上显示结果
- 防止 PHP 在新页面中显示结果
- jquery jqgrid 不显示结果,具体取决于 JSON 对象中的参数
- Angular-如何显示结果,仅在未选中时显示
- backbone.js视图没有't由于异步获取而显示结果;t渲染
- jqueryajax帖子将我发送到操作页面,并且不会显示结果数据
- 添加两个数字,并使用Javascript在文本框中显示结果
- 接受用户输入,与JSON数据匹配,并以javascript显示结果
- 自动完成 JQuery 不显示结果
- 控制台.log或显示结果的函数
- 提交表单,使用脚本处理信息,并在同一页面上显示结果
- AJAX 实时搜索仅当结果以相同的第一个字母开头时才显示结果