Hallo
Als js-Laie habe ich nun mit viel Aufwand endlich eine Lösung gefunden um einen Text (durch drauf klicken) zu markieren um ihn danach mit CTRL+C in ein Feld einzufügen.
<script type="text/javascript">
function myFunction(id)
{
/* Get the text field */
if (id == 1)
var copyText = document.getElementById("myInput1");
if (id == 2)
var copyText = document.getElementById("myInput2");
if (id == 3)
var copyText = document.getElementById("myInput3");
/* Select the text field */
copyText.select(id);
/* Copy the text inside the text field */
document.execCommand("copy");
}
</script>
Die Nummern 1,2,3 (myFunktion(1), myInput1) füge ich mit php ein, den Text lese ich aus einer Datei, es können also auch viel mehr "input-Felder" sein.
Gibt es eine Möglichkeit im Java-Script eine Schlaufe zu machen, statt jede Zeile mit der Nummer zu definieren?
Viele Grüsse und Dank zum voraus, nebbiolo
Als js-Laie habe ich nun mit viel Aufwand endlich eine Lösung gefunden um einen Text (durch drauf klicken) zu markieren um ihn danach mit CTRL+C in ein Feld einzufügen.
HTML-Code:
<form> <input type='text' size='120' onclick='myFunction(1)' id='myInput1' value='AAA'><br /> <input type='text' size='120' onclick='myFunction(2)' id='myInput2' value='BBB'><br /> <input type='text' size='120' onclick='myFunction(3)' id='myInput3' value='CCC'><br /> etc. <input type="submit" value="Kopieren!" formaction=""> </form>
function myFunction(id)
{
/* Get the text field */
if (id == 1)
var copyText = document.getElementById("myInput1");
if (id == 2)
var copyText = document.getElementById("myInput2");
if (id == 3)
var copyText = document.getElementById("myInput3");
/* Select the text field */
copyText.select(id);
/* Copy the text inside the text field */
document.execCommand("copy");
}
</script>
Die Nummern 1,2,3 (myFunktion(1), myInput1) füge ich mit php ein, den Text lese ich aus einer Datei, es können also auch viel mehr "input-Felder" sein.
Gibt es eine Möglichkeit im Java-Script eine Schlaufe zu machen, statt jede Zeile mit der Nummer zu definieren?
Viele Grüsse und Dank zum voraus, nebbiolo
Kommentar