HTML 具有不同页面重定向的表单,具体取决于输入

HTML form with different page redirection depending on input

我想在 HTML 中有一个盒子,比如这个:

特别的事情,我只需要使用 HTML(没有 PHP 或需要服务器或特定安装的特定语言)。

原因是它用于 HTML 将从 USB 密钥打开的页面,而不是网站,并且它必须可供任何 non-expert 使用人。所以不需要 web-server 配置或安装,例如 PHP,如果我是对的。

考虑不使用Form,只使用Javascript函数。

我不确定这是否可能出于安全原因而无法实现,但这可能是一个解决方案...

function redirect() {
  var input = document.getElementById("stuff");
  window.location = input.value;
}
<span>NOM:</span>
<input type="text" id="stuff"></input>
<br>
<input type="button" onclick="redirect()" value="Submit"></input>

由于 Anders Anderson 的回答,我设法完成了我需要做的事情。这是那些有兴趣做类似事情的人的代码。首先,对于 Javascript

function redirect() {
  var answergiven = document.getElementById("answergiven");
  var realanswer = document.getElementById("realanswer");
  var nextpage = document.getElementById("nextpage");

  if(answergiven.value.toLowerCase() == realanswer.value.toLowerCase()){
      window.location = nextpage.value;
  }
  else{
      alert('Wrong answer, please try again.');
  }

  return false; // prevent further bubbling of event
}

而对于 HTML 部分,有两个隐藏变量决定真正的答案、要转到的下一页和答案的文本字段

    <form name="myform" onSubmit="return redirect()">
    <span>Réponse:</span>
    <input type="text" id="answergiven" />
    <input name="tosubmit" type="submit" value="Submit" />
    <input type="hidden" id="realanswer" value="theanswer" />
    <input type="hidden" id="nextpage" value="thenextpage.html" />
    </form>