1

So I have this drop down list

function copyThis(text) {
  window.prompt("Copy this : ", text);
};
<!DOCTYPE html>
<html>

<body>

  <select class="wrap" onchange="copyThis(this.value)">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
  </select>
</body>

</html>

Currently using the above it does not let me highlight or select the option that is chosen in the list. Is there a better way by double clicking and highlight the selected option so that i can Ctrl + C or Mouse right click and copy

1 Answers1

1

How about a "copy" button:

function copyThis(text) {
  window.prompt("Copy this : ", text);
};

$("#copy").click(function () {
  window.prompt("copy this:", $("#cars option:selected").text());
});
<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>

  <select id="cars" class="wrap">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
  </select>

  <button id="copy">copy</button>

</body>

</html>
elementzero23
  • 1,171
  • 2
  • 13
  • 30