title: Display selected text in a jsp page
body: <p>Hi I am a newbie in JSP and was trying to show the selected value in a header as a dynamic text. But every time I select it shows the option value not the text. below is what I have tried.</p>
  
  <p>Html drop down</p>
  
  <pre><code>&lt;select id="country" name="country_code"&gt;
         &lt;option value="1"&gt;Puerto Rico&lt;/option&gt;
         &lt;option value="63"&gt;Philippines&lt;/option&gt;
         &lt;option value="others"&gt;Others&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>JSP tag</p>
  
  <pre><code>    &lt;%
          String countrycd = request.getParameter("country_code");
          String countryTxt = request.getParameter("country_code");
      %&gt;
  </code></pre>
  
  <p>This is my script</p>
  
  <pre><code>    &lt;script&gt;
          document.getElementById("country").value = '&lt;% out.print(countrycd); %&gt;';
          var e= document.getElementById("country");
          var str = e.options[e.selectedIndex].text;
          alert(str);
      &lt;/script&gt;
  </code></pre>
  
  <p>This is my html code where I need to show the selected text instead of value for example if user selects Philippines it should show as Philippines not the code 63</p>
  
  <pre><code>&lt;h2&gt;By Country: &lt;% out.print(countrycd);&lt;/h2&gt;
  </code></pre>
  
  <p>Any help would be really appriciated!</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>Current Output</p>
  
  <blockquote>
    <p>From drop down philipines is selected in header it shows: By Country:
    63</p>
  </blockquote>
  
  <p>Expected output:</p>
  
  <blockquote>
    <p>From drop down if philipines is selected it should show</p>
    
    <p>By Country: Philipines not 63.</p>
  </blockquote>