admin管理员组

文章数量:1323205

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>

本文标签: