简体   繁体   English

选择两个选项-单击转到-重定向到url

[英]Select two options - click go - redirect to url

I cannot find any help on a script I need to implement on a website. 我找不到需要在网站上实施的脚本的任何帮助。

  1. SELECT ONE
  2. The visitor selects a, b, c or d 访客选择a,b,c或d
  3. SELECT TWO , they then SELECT TWO ,然后
  4. select 1, 2, 3, 4, 5, 6 - to - 14 选择1,2,3,4,5,6-至-14
  5. GO

they then click go which takes them to a page that corresponds with their selections. 然后单击“ go ,将其带到与其选择相对应的页面。

I should add that the options are not chained in that selecting option 1 does not alter option 2's selects. 我应该补充一点,就是选项1不会改变选项2的选择,所以选项没有被链接。 They stay the same. 他们保持不变。

Any help appreciated. 任何帮助表示赞赏。

If you want to process the form inputs on the server, you must use a server-side language like PHP. 如果要在服务器上处理表单输入,则必须使用服务器端语言,例如PHP。 Here's simple tutorial to achieve this: http://www.tizag.com/phpT/forms.php/ 这是实现此目的的简单教程: http : //www.tizag.com/phpT/forms.php/

If you want to process the form on the client side, use JavaScript to gather selected values in the form and then do something with those values. 如果要在客户端处理表单,请使用JavaScript收集表单中的选定值,然后对这些值进行处理。 You do not need to do redirect to another page because you can attach an event handler to the form Submit's button. 您无需重定向到另一个页面,因为您可以将事件处理程序附加到表单“提交”按钮上。

For example: 例如:

The HTML forms looks like this: HTML表单如下所示:

<form>
    <select name="firstSelect" id="firstSelect"> ...
      ...
    </select>
    <select name="secondSelect" id="secondSelect">
      ...
    </select>
    <input type="submit" name="submit" id="submit" value="Submit form" onclick="javascript: return processForm();" />
</form>

Inspecting the submit button of the form: 检查表单的提交按钮:

<input type="submit" name="submit" value="Submit form" 
 onclick="javascript: return processForm();" />

What this code block will do is trigger javasript function processForm() when the user clicks on the submit button. 当用户单击提交按钮时,此代码块将执行触发javasript函数processForm()的操作。 Also, it will prevent a page to redirect. 同样,这将阻止页面重定向。

The processing function looks like this: 处理功能如下所示:

<script>
   function processForm()
   {
       // fetch selected values from the form and do actions based on that
       var firstValue = $('form select#firstSelect').val();
       var secondValue = $('form select#secondSelect').val();

       // prevent form redirection 
       return false;
   }
</script>

Example of actions you might perform are hide/show certain resulting divs on the page, display results of the form processing etc. 您可能执行的操作示例是在页面上隐藏/显示某些结果div,显示表单处理的结果等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM