简体   繁体   English

如何基于两个下拉菜单选择进行页面重定向?

[英]How to do Page Redirection based on two drop down menu selections?

I want to create a form from my website where the user has two dropdown boxes with values say body height and type of build . 我想在我的网站上创建一个表单,其中用户有两个下拉框,其值分别为body heighttype of build Depending on their selection, they would be directed to a page with information about their specific/selected build. 根据他们的选择,他们将被定向到一个页面,其中包含有关其特定/选定构建的信息。

To have an idea of what I want to create, here is the form i wish to display.. the use if for a BMX bike guide 要了解我要创建的内容,以下是我要显示的表格。.如果用于BMX自行车指南

function goToPage() { var type = document.getElementById("type").value; 函数goToPage(){var type = document.getElementById(“ type”)。value; var height = document.getElementById("height").value; var height = document.getElementById(“ height”)。value; if(type !== 0 && height !== 0) { window.location = "http://www.maltabmx.com/About.html?jtype=" + 1 + "&height=" + 1; if(type!== 0 && height!== 0){window.location =“ http://www.maltabmx.com/About.html?jtype=” + 1 +“&height =” + 1;
  window.location = "http://www.maltabmx.com/Footage.html?jtype=" + 1 + "&height=" + 2; window.location = "http://www.maltabmx.com?jtype=" + 1 + "&height=" + 3; window.location = "http://www.maltabmx.com/About.html?jtype=" + 1 + "&height=" + 4; window.location = "http://www.maltabmx.com/Footage.html?jtype=" + 1 + "&height=" + 5; window.location = "http://www.maltabmx.com?jtype=" + 1 + "&height=" + 6; } } 
 <form> <p> Type of Terrain: </p> 

Select Street/Park Dirt Racing 选择街道/公园泥土赛车

 <p>Body Height</p> <select id="height"> <option value="0" id="Select">Select</option> <option value="1" id="5ft">4ft</option> <option value="2" id="5.5ft">4.25ft</option> <option value="3" id="5.5ft">4.50ft</option> <option value="4" id="6ft">4.75ft</option> <option value="5" id="5ft">5ft</option> <option value="6" id="5.5ft">5.25ft</option> <option value="7" id="6ft">5.50ft</option> <option value="8" id="5ft">5.75ft</option> <option value="9" id="5.5ft">6ft</option> <option value="10" id="6ft">6.25ft</option> </select> <br /><br /> <input onclick="goToPage();" type="button" value="Submit" /> </form> 
<html>
 <head>

  $(document).ready(function() {

      $('#submit').click(function(){ 

      var type= $("#type").val();
      var height = $("#height").val();

      window.location.href = 'http://www.someweb.com/page.php?type='+type+'&&height='+height;

    });

 });

  </head>
  <body>

 <form>
 <p> Type of Terrain: </p>

  <select id="type">
    <option value="1" id="Street">Street</option>
    <option value="2" id="Dirt">Dirt</option>
    <option value="3" id="Park">Park</option>
    <option value="4" id="Racing">Racing</option>
    </select>

    <p>Body Height</p>
    <select id="Height">
    <option value="1" id="5ft">5ft</option>
    <option value="2" id="5.5ft">5.5ft</option>
    <option value="3" id="6ft">6ft</option>

    </select>

    <br /><br />

    <input id="submit" type="submit" value="Submit" />

    </form>
  </body>
</html>

So, i changed the code above. 因此,我更改了上面的代码。 Let me know if you still hve some questions. 让我知道您是否还有其他问题。

PS: normally to redirect or pass values to other pages you would want to use the jquery $.post, $.get or $.ajax methods instead of windows.location.href. PS:通常将值重定向或传递到其他页面,您需要使用jquery $ .post,$。get或$ .ajax方法而不是windows.location.href。

Have a look here http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/ 在这里看看http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

EDITED - Working solution: http://jsfiddle.net/YXW7K/13/ 编辑-工作解决方案: http : //jsfiddle.net/YXW7K/13/

暂无
暂无

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

相关问题 根据两个菜单选择转到页面 - Go to page based on two menu selections 如何基于AngularJS中的下拉菜单项更改页面标题 - How to change title of page based on drop down menu items in AngularJS 基于表单输入值,2如何生成选择4 4下拉菜单w从数据库中行/记录数据,将在选定时预填充表单? - Based on a forms input value, how 2 generate selections 4 a drop down menu w row/record data from a database that will prefill a form when selected? 根据先前的选择下拉选择 - Drop down selections based on Previous selection 如何在下拉菜单中显示数据库中的列数据作为选择? - How can I show column data from my databasel in a drop down menu as selections? 我如何显示数据库中的列值作为下拉菜单的选择? - How can i display a columns values from my database as selections for my drop down menu? 如何使用数据库中的行/记录数据为下拉菜单生成选择项,从而在选择时预填表格? - How to generate selections for a drop down menu with row/record data from a database that will prefill a form when selected? 如何根据下拉菜单中的选项更改页面的样式表 - how to change the style sheet of a page based on the option from the drop-down menu php下拉列表,每个“选项”带有“两个值”,并且有多个选择 - php drop down list with “two values” for each “option” and multiple selections 基于另一个下拉菜单的下拉菜单项 - Drop down menu items based on another drop down menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM