最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to get selected value from select tag using javascript and go to another page using that value - Stack Overflow

programmeradmin2浏览0评论

I have a select tag where it contains some values, as shown below:

         <select id="menu" SIZE=6 onChange="go()">
          <option value="">Select city</option>
    <option value="delhi" >delhi</option>  
    <option value="kolkata" >kolkata</option>  
    <option value="mumbai" >mumbai</option>
           </select>

Now i am using below script for this, where it get the selected value from the drop down,

      <script>
        function go(){

var sel = document.getElementById('menu');
       var sv = sel.options[sel.selectedIndex].value;

              //  here i  need to make a specific link using this selected drop down value


          }

          </script>

I just need to know how can i make use of this selected value and go to specific link like

       window.location.href='getCityDetails.jsp?c=sv'; // this is not working properly 

Can anyone suggest me best solution for this.

I have a select tag where it contains some values, as shown below:

         <select id="menu" SIZE=6 onChange="go()">
          <option value="">Select city</option>
    <option value="delhi" >delhi</option>  
    <option value="kolkata" >kolkata</option>  
    <option value="mumbai" >mumbai</option>
           </select>

Now i am using below script for this, where it get the selected value from the drop down,

      <script>
        function go(){

var sel = document.getElementById('menu');
       var sv = sel.options[sel.selectedIndex].value;

              //  here i  need to make a specific link using this selected drop down value


          }

          </script>

I just need to know how can i make use of this selected value and go to specific link like

       window.location.href='getCityDetails.jsp?c=sv'; // this is not working properly 

Can anyone suggest me best solution for this.

Share Improve this question asked Oct 5, 2013 at 11:31 puneetjavapuneetjava 1653 gold badges7 silver badges20 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1
 <script>
    function go(){

   var sel = document.getElementById('menu');
   var sv = sel.options[sel.selectedIndex].value;
    window.location.href='getCityDetails.jsp?c=' + sv;

      }

      </script>

Hope it helps you

HTML :

<select id="menu" SIZE=6 onChange="go(this.value)">
    <option value="">Select city</option>
    <option value="delhi" >delhi</option>  
    <option value="kolkata" >kolkata</option>  
    <option value="mumbai" >mumbai</option>
</select>

Javascript :

function go(desination){
    if (destination != ''){
         window.location.href='getCityDetails.jsp?c=' + desination;
    }
}

you need to concatenate the string properly. try this:

window.location.href='getCityDetails.jsp?c=' + sv;

-- You can use--

var TaskType = document.form1.SelTaskType.value;

-- TaskType will display selected option from below

<select id="SelTaskType" name="SelTaskType" >
<option selected>-- select --</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论