简体   繁体   English

如何使用提交按钮组合值添加多个下拉表单并将另一个 html 页面名称添加到 go

[英]How to add multiple dropdown form with submit button combine value and make another html page name to go to it

I want the submit button to act on the combined values in the two didferent dropwdown menu's in the form.Which will be a html page name.我希望提交按钮对表单中两个不同下拉菜单中的组合值起作用。这将是 html 页面名称。

For example... west and winter is a different option which will creat "westwinter.html" then west and summer is a different option which will make "westsummer.html".例如...west 和winter 是一个不同的选项,将创建“westwinter.html”,然后west 和summer 是一个不同的选项,将创建“westsummer.html”。 and clicking submit button the created page will load.I have already created such types of html page named (ex. westwinter.html).并单击提交按钮,创建的页面将加载。我已经创建了名为(例如 westwinter.html)的此类 html 页面。

I'm struggeling for days to make this work.我努力了好几天才能完成这项工作。 I feel some how this must be possible.我觉得这一定是可能的。 Please help!请帮忙!

This is the code I use.这是我使用的代码。 When I replace the value to a page name (ex. westsummer.html).当我将值替换为页面名称时(例如 westsummer.html)。 The page will be loaded on submit (go).该页面将在提交 (go) 时加载。 I want the values of the first dropdown and second dropdown to be counted and the result should be a page name on submit.我希望计算第一个下拉列表和第二个下拉列表的值,结果应该是提交时的页面名称。 Finaly there should be 16 different html page name.最后应该有 16 个不同的 html 页面名称。 Iwant this solution with jQuery or javascript.我想要这个带有 jQuery 或 javascript 的解决方案。

  <div class="selCont">
  <h2>pick an option</h2>

  <select id="selection" name="selection">
  <option value="1">West</option>
  <option value="2">East</option>
  <option value="3">North</option>
  <option value="4">South</option>
  </select>

  <select id="selection" name="selection">
  <option value="1">Winter</option>
  <option value="2">Spring</option>
  <option value="3">Summer</option>
 <option value="4">Fall</option>

 </select>
 <button class="go-btn" type="submit">Go</button>
 </div>

Firstly, let's set unique IDs for the select tags, and lets set the values to the actual strings (we could keep them numeric and perform a switch on them later to determine their value, but it's easier this way):首先,让我们为 select 标签设置唯一的 ID,然后将值设置为实际的字符串(我们可以将它们保持为数字并稍后在它们上执行开关以确定它们的值,但这样更容易):

<select id="direction" name="selection">
    <option value="west">West</option>
    <option value="east">East</option>
    <option value="north">North</option>
    <option value="south">South</option>
</select>

<select id="season" name="selection">
    <option value="winter">Winter</option>
    <option value="spring">Spring</option>
    <option value="summer">Summer</option>
    <option value="fall">Fall</option>
</select>

Next, let's write a function to compose a link using the values from those select tags.接下来,让我们编写一个 function 来使用来自这些 select 标记的值组成一个链接。 I've used document.querySelector here, but you can easily change it out for jQuery if you'd like:我在这里使用了document.querySelector ,但如果您愿意,您可以轻松地将其更改为 jQuery:

function getLink() {
    var direction = document.querySelector("#direction").value;
    var season = document.querySelector("#season").value;
    //Assuming that the html files are in the same folder as the current page
    return "./" + direction + season + ".html";
}

Finally, let's update our button to change the page location to the new link when clicked:最后,让我们更新我们的按钮以在点击时将页面位置更改为新链接:

<button class="go-btn" type="submit" onClick="window.location.href = getLink()">Go</button>

Here's everything altogether:这是所有的一切:

 <.DOCTYPE html> <html lang="en"> <body> <div class="selCont"> <h2>pick an option</h2> <select id="direction" name="selection"> <option value="west">West</option> <option value="east">East</option> <option value="north">North</option> <option value="south">South</option> </select> <select id="season" name="selection"> <option value="winter">Winter</option> <option value="spring">Spring</option> <option value="summer">Summer</option> <option value="fall">Fall</option> </select> <button class="go-btn" type="submit" onClick="window.location.href = getLink()" >Go</button> </div> </body> <script> function getLink() { var direction = document.querySelector("#direction");value. var season = document.querySelector("#season");value. return "./" + direction + season + ";html"; } </script> </html>

暂无
暂无

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

相关问题 提交后,在另一个HTML页面上显示表单字段值 - Display form field value on another html page, after submit 如何制作它以便您无法单击“开始”提交表单(iPhone),但必须点击“提交”按钮? - How do I make it so that you cannot click “GO” to submit the form (iPhone), but must tap the “submit” button? 表单验证后如何将提交按钮链接到另一个页面? - How to link submit button to another page after form validation? 由于Y页面需要X页面的处理数据,因此如何使html表单首先提交到X页面等待一会儿再提交到另一个Y页面。 - How to make html form to submit to X page first wait for a while and submit to another Y page because Y page needs processed data of X page 单击提交按钮后如何在不通过服务器的情况下如何从HTML页面的形式获取数据到另一个页面 - How to get data from a form of an Html page to another page after clicking submit button, without going through the Server 带有提交按钮的下拉表单 - Dropdown form with submit button 如何使用 JavaScript 函数向 HTML 表单添加提交按钮? - How to add submit button to an HTML form with JavaScript function? 如何选择表格到另一个页面? - How do I make a form selection go to another page? 我有一个按钮可以重定向另一个表单我希望下拉列表中的该按钮值作为下一页表单中的选定选项? - I have a button that redirects the another form I want that button value in the dropdown as a selected option in the next page form? 如何添加按钮以提交表单? - How to add a button to submit a form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM