Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read selected value from select tag of HTML using javascript code

My HTML code is as:

 <div id="detail">
    <div class="d_left">
    Page <strong>1</strong> of 107
    </div>
    <div class="d_center">
    <table>
    <tr>
    <td><a href="#">Previous</a> | <a href="#">Next</a>
    <img src="/webProject/store/images/arrow.png" align="absmiddle" alt="">
    </td></tr></table>
    </div>
    <div class="d_right">
    Sort by:
     <select name="featured" size="1" id="item1">
          <option>Featured Items1</option>
          <option>Featured Items2</option>
          <option>Featured Items3</option>
          <option>Featured Items4</option>
        </select>
    </div>
</div>

Now, I want to read selected value from <select name="featured" size="1" id="item1">. How can I do this using JavaScript?

like image 575
Romi Avatar asked Jul 13 '11 06:07

Romi


1 Answers

function delivery(x){
      var country = x.value;
      document.getElementById('lala').innerHTML = country;
}
<div id="lala"></div>
<form action="" method="post">
<select name="country" id="country" onChange="delivery(this)">
    <option value='lala'>Select Country</option>
    <option value='United_Kingdom'>United Kingdom</option>
    <option value='Russia'>Russia</option>
    <option value='Ukraine'>Ukraine</option>
    <option value='France'>France</option>
    <option value='Spain'>Spain</option>
    <option value='Sweden'>Sweden</option>
</select>
</form>

Here is how i solved my problem for selecting eu countries (i have removed most of them to make my codes shorter).. as im new to javascript.. i still need to learn javascript libraries.

like image 61
Gurung Avatar answered Sep 17 '22 17:09

Gurung