puneetjava
puneetjava

Reputation: 165

How to get selected value from select tag using javascript and go to another page using that value

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.

Upvotes: 1

Views: 24589

Answers (4)

Rahul Sawant
Rahul Sawant

Reputation: 1264

-- 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>

Upvotes: 0

Oki Erie Rinaldi
Oki Erie Rinaldi

Reputation: 1863

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;
    }
}

Upvotes: 1

Andrei C
Andrei C

Reputation: 812

you need to concatenate the string properly. try this:

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

Upvotes: 0

Neeraj
Neeraj

Reputation: 4489

 <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

Upvotes: 1

Related Questions