提交表单后重定向,并在 URL 中输入用户


Redirecting after form submission with user input in the URL

我需要有一个表单,填写后将创建一个变量,然后在 url 中使用该变量转到 url

像这样的东西(但有效):)

<form action="?????" method="?????">
Number: <input type="text" name="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL">
</form>

当提交被按下时,我需要它转到 http://somewhere.com?url=VALUEHERE

有什么想法吗?

使用 method="GET" 将变量放在 url 中:

<form action="http://somewhere.com/" method="GET">
    Number: <input type="text" name="url" value="" /><br />
    <input type="submit" name="submit" value="Goto URL" />
</form>

发布此表格将转到 http://somewhere.com/?url=USER_INPUT_URL

与 1st 不同。 不需要表单,为文本字段添加一个名为"id"的属性,然后定义一个javascript函数来检索文本字段的值,然后做跳转,希望有用。

<form action="?????" method="?????">
Number: <input id="url1" type="text" name="url1" value=""><br>
<input type="button" name="submit" value="gotoURL()">
</form>
<script>
function gotoURL(){
window.location='http://somewhere.com?url='+document.getElementById('url1').value;
}
</script>
<form>
Number: <input type="text" name="url1" id="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL" onclick="redirect()">
</form>
<script>
function redirect()
{
  window.location='http://somewhere.com?url=' + document.getElementByID('url1').value;
}
</script>