Avatar billede koldstar Nybegynder
08. maj 2002 - 14:24 Der er 8 kommentarer og
1 løsning

ctrl + c ?? evt. javascript istedet

hejsa. hvordan kan lave et link som automatisk markerer og kopierer indholdet af en textbox??
Avatar billede Slettet bruger
08. maj 2002 - 14:27 #1
??Uddyb venligst.
Avatar billede koldstar Nybegynder
08. maj 2002 - 14:35 #2
lidt lige som her: http://www.codelifter.com/main/javascript/norightclick1.html
den skal bare kopiere teksten samtidig
Avatar billede Slettet bruger
08. maj 2002 - 14:38 #3
==========================================
HIGHLIGHTING FORM TEXTAREAS ON MOUSE CLICK
==========================================
 
Copyright 2001 by www.CodeBelly.com
Do *not* remove this notice.



=============
INSTRUCTIONS:
=============

Insert the scripts below in the page as noted. No changes
are needed. Read through the General Rules for an under-
standing of the requirements.

For multiple instances, change the function name, the
form name, and the textarea name for each case.

General Rules:

1.
The FORM must have a NAME="something" as shown in the
HTML for the form (below, see NAME="TheForm"). 

2.
The TEXTAREA must have a NAME="something" as shown in the
HTML for the form (below, see NAME="TheText").

3.
The names used in the form must agree with those used in
the JavaScript script.  See:
 
    document.TheForm.TheText.focus();
    document.TheForm.TheText.select();

4.
You can set the text to wrap by setting wrap="on" (or set
it not to wrap with wrap="off") in the textarea tag.



============
THE SCRIPTS:
============



Step One - The JavaScript Header Script
---------------------------------------

Put the following script in the head of the page.  The
form name and textarea name in the document reference
in the script must conform to the names used in the
form in the body of the page.

<script>
// Copyright 2001 by www.CodeBelly.com
// Do *not* remove this notice.
function selectText(){
document.TheForm.TheText.focus();
document.TheForm.TheText.select();
}
</script>



Step Two - The Link That Selects The Text
-----------------------------------------

Use the following code for a link which, when clicked,
will select the text in the textarea.

<a href="java script:selectText()">Click to Select</a>



Step Three - The Form and Its Textarea
--------------------------------------

Put the following form in the <body> of the page where
you wish the textarea to appear.  Alter the text as
needed.  Remember that the form name and textarea name
must agree in the form and in the script.

<form NAME="TheForm">
<textarea rows="12" cols="62" NAME="TheText" wrap="off">
This is the text in the textarea.  Change it to suit.
</textarea>
</form>
Avatar billede koldstar Nybegynder
08. maj 2002 - 14:40 #4
okay, det skal nok være javascript! jeg forestiller mig noget i denne stil:

function selectText(){
document.Form1.Text1.focus();
document.Form1.Text1.select();
//og så noget a' la' document.Form1.Text1.copy();
}
Avatar billede koldstar Nybegynder
08. maj 2002 - 14:40 #5
ja, det markerer teksten, men det kopierer den ikke
Avatar billede =maddog= Nybegynder
08. maj 2002 - 14:40 #6
for at markere teksten
txtR = document.formnavn.textareanavn.createTextRange();
for at kopiere til clipbaord
txtR.execCommand("copy",false,"");
Avatar billede koldstar Nybegynder
08. maj 2002 - 14:48 #7
=maddog= SÅDAN!!!!
Avatar billede =maddog= Nybegynder
08. maj 2002 - 14:48 #8
hmm. sådan
<script>
function clip() {
document.f.t.select()
document.execCommand("copy",false,"");
}
</script>
Avatar billede =maddog= Nybegynder
08. maj 2002 - 14:50 #9
glad for at være til hjælp
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester