我有一个表单,其中包含可缓存项目的Javascript填充集合,以及由用户输入的ID为文本框。我希望表单提交将用户重定向到来自其他调用的JSON响应。当我直接进入浏览器时,其余的URL起作用,但是将它转移到html和js会击败我。点击提交时,提交表单不会执行任何操作。html onsubmit无法启动Javascript功能
我的形式 -
<form id="query" action="get" onsubmit="return restLink();">
<td>
<select id="selectCacheableItemType">
<option>Select a Cacheable Item Type</option>
</select>
</td>
<td>
Cacheable item Id: <input type="text" id="cacheableId"><br>
</td>
</form>
的缓存项目类型在这里居住 -
window.onload = function cacheItemType(){
var select = document.getElementById("selectCacheableItemType");
var options = ["1", "2", "3", "4", "5", "6","7"];
for(var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
};
和restLink()函数 -
function restLink() {
cachetypename = document.getElementyId('selectCacheableItemType').getValue();
cacheid = document.getElementyId('cacheableId').getValue();
return window.location.href = "http://localhost:8080/rest/query/"+ cachetypename + "/" + cacheid;
}
任何帮助深表感谢。
哪里提交按钮?您的HTML无效。你不能在td标签周围有表格。 – epascarello 2014-10-28 14:27:58
您是否尝试添加提交输入?并在该提交输入上进行onclick事件? – guramidev 2014-10-28 14:28:35
设置'window.location.href'会让你转到那个页面。其次,当你的JavaScript中有错误时,你的函数将不会被调用/ finnished。在浏览器中打开您的开发人员工具 - >控制台,查看您提交时是否返回错误。 – 2014-10-28 14:30:40