Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Get text if I select some value from drop list HTML app script

I have this code to get some text if I select a value from the drop list:

<!DOCTYPE html>
<html>
<body>

<div id="addOrderPrompt">
    <center>
    <form> 
      <div id="containerT0"><label for="example">Drop List:</label>
        <select name="exchange" id="exchange">
          <option value="first" rel="firstTarget">First</option>
          <option value="second" rel="secondTarget">Second</option>
        </select>
       </div>
        <a href="https://www.google.com" target="_blank" class="firstTarget">Google</a>
        <a href="https://www.facebook.com" target="_blank"class="secondTarget">Facebook</a>
      </select>
    </form>
    </center> 
</div>

</body>
</html>

I want to hide links I show it if I select some value from the droplist. For example, if I select from the drop list 'First' I want to see just a google link, and if I select 'second' just see the Facebook link.

This is my result:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can get the selected option from JavaScript using the onchange event and handle the visibility of links using the display property. Here's an example:

function handleChange() {
  var userValueElement = document.getElementById("exchange");
  var userValue = userValueElement.options[userValueElement.selectedIndex].text;
  if (userValue == "First") {
    document.getElementById('google').style.display = 'inline';
    document.getElementById('facebook').style.display = 'none';
  } else if (userValue == "Second") {
    document.getElementById('google').style.display = 'none';
    document.getElementById('facebook').style.display = 'inline';
  }
}
<!DOCTYPE html>
<html>

<body>

  <div id="addOrderPrompt">
    <center>
      <form>
        <div id="containerT0"><label for="example">Drop List:</label>
          <select name="exchange" id="exchange" onchange="handleChange()">
            <option value="first" rel="firstTarget">First</option>
            <option value="second" rel="secondTarget">Second</option>

          </select>
        </div>

        <a id="google" href="https://www.google.com" target="_blank" class="firstTarget">Google</a>
        <a id="facebook" href="https://www.facebook.com" target="_blank" class="secondTarget" style="display: none">Facebook</a>
        </select>
      </form>
    </center>
  </div>

</body>

</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!