简体   繁体   English

根据下拉选择和文本框值更改网址

[英]Change url based on drop down selection & text box value

I have a very simple form. 我有一个非常简单的表格。 I'm trying to redirect the page based on dropdown value selected and value entered in the text box. 我正在尝试根据所选的下拉值和在文本框中输入的值来重定向页面。

My form looks like this: http://devilscircuit.com/new/test.html 我的表单如下所示: http : //devilscircuit.com/new/test.html

It just has a select box, a text box & a submit button. 它只有一个选择框,一个文本框和一个提交按钮。 I'm trying to redirect the page once user clicks on submit button. 我试图在用户单击“提交”按钮后重定向页面。

I'm not very well versed with JavaScript. 我不太了解JavaScript。

Can someone help me with it? 有人可以帮我吗?

My current JavaScript looks something like this: 我当前的JavaScript看起来像这样:

<script>
function setURL(){
var dt_value = document.getElementById("dt_id").value;
var dt_value2 = document.getElementById("dt_id2").value;
var sjdurl =  "http://parshwatax.com/devilscircuit2/+dt_value2/index.php?     
controller=search&search_query="+dt_value;
window.location.href=(sjdurl);
}
</script>

HTML Is below: HTML如下:

<h4 class="title2">Search Your Picture</h4>
<label>Please Select an Event </label>
<select style="width:205px; margin-left:68px;" id="dt_id2"> 
<option value="shop1">GURGAON'14</option>
<option value="shop2">NOIDA'13</option>
<option value="shop3">LUDHIANA'12</option>
</select> </br>

<label for="dt_id">Please enter your BIB number </label>
<input type="Text" id="dt_id" maxlength="25" size="23" style="margin: 5px 21px;"/> </br>
                    <input type='button' onclick='setURL()' value='SUBMIT' style="margin: 10px 208px;"> 

Please help me fix the redirect. 请帮助我修复重定向。 THanks in advance. 提前致谢。

You have a couple issues. 你有几个问题。 One is your "sjdurl" concatenation has a syntax error. 一种是您的“ sjdurl”串联具有语法错误。 Should be 应该

var sjdurl =  "http://parshwatax.com/devilscircuit2/"+dt_value2+"/index.php?     
controller=search&search_query="+dt_value;

Another issue is your retrieving the selected value of your "dt_id2" select field incorrectly. 另一个问题是您错误地检索了“ dt_id2”选择字段的选定值。 It should be like: 应该是这样的:

var dt_select = document.getElementById("dt_id2");
var dt_value2 = dt_select.options[dt_select.selectedIndex].value;

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

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