Html 获取表单中的文本框值
这是我的代码:Html 获取表单中的文本框值,html,jsp,Html,Jsp,这是我的代码: <form method="get" action="http://google.com#q=<%= request.getParameter("myname") %>" target="_blank"> Enter your name: <input type="text" name="name"><input type="submit"> </form> 输入您的姓名: 我需要获取在文本框中输入的值,
<form method="get" action="http://google.com#q=<%= request.getParameter("myname") %>" target="_blank">
Enter your name: <input type="text" name="name"><input type="submit">
</form>
输入您的姓名:
我需要获取在文本框中输入的值,并将其附加到动作参数中的URL。如何?上述代码为表达式标记返回null。html:
<form method="get" action="" target="_blank" id="myForm">
Enter your name: <input type="text" name="name" id="txtName"><input type="submit" id="submit" value="Submit">
</form>
请注意,如果希望重定向发生在同一页面上,请使用window.location.href=url
而不是window.open
希望能有所帮助。你得到了“myname”作为参数,你的输入名在哪里?
name
Ya我改变了它,但它不起作用,朋友。现在,正如@Gal所说的那样尝试了js。工作。谢谢。在OP没有要求的情况下建议jQuery解决方案。
document.getElementById('submit').oncick = function() {
var val = document.getElementById('txtName').value;
window.open('http://google.com?q=' + encodeURIComponent(val));
return false;
}