Ik zoek een scriptje die je textarea opslaat dmv een button te drukken.

iets met onclick misschien?



function download(text, name, type) {
var a = document.getElementById("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
}

<a href="" id="a">click here to download your file</a>
<button onclick="download('file text', 'myfilename.txt', 'text/plain')">Create file</button>

wil maar niet werken
Kan je vraag misschien verkeerd begrepen hebben, maar zoek je zoiets?



<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        
        <script type="text/javascript">
            function download(text, name, type) {
                var a = document.getElementById('a');
                var file = new Blob([text], {type: type});
                a.href = URL.createObjectURL(file);
                a.download = name;
            }
        </script>
    </head>
    <body>
        <textarea id="text"></textarea>
        <a href="#" id="a">Click here to download your file</a>
        <button onclick="download(document.getElementById('text').value, 'myfilename.txt', 'text/plain');">Create File</button>
    </body>
</html>
function download(filename, content)
{
var a = document.createElement('a');
linkDownload(a, filename, content);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

[size=xsmall]Toevoeging op 13/10/2015 20:36:12:[/size]

Anna Smit op 13/10/2015 20:34:13

function download(filename, content)
{
var a = document.createElement('a');
linkDownload(a, filename, content);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

<input type="image" src="http://iconmaker.00laboratories.com/images/tools/icon_save.png" id="HOI" value="save it"
onclick="download('jeopdracht.txt', 'content');">

<textarea id="inhoud" rows="10" cols="50"?>
</textarea>


Nu wil ik niet dat er in mijn gedownloade txtbestand: content staat maar dat er wat ik heb geschreven in mijn textarea opslaat

Ik hoop dat je me kan helpen! :)


Ik weet niet of je het volgende bedoelt maar volgens mij lijkt het er wel op dus helpt het je misschien (voor als je nog een antwoord zocht):

Een textarea met de naam comment zonder actie (zodat ie op zijn eigen pagina blijft).


<form method="post" action="">
Uw bericht: <span class="error">* <?php echo $commentErr; ?></span><br />
<textarea name="comment" rows="5" cols="40"><?php echo $comment; ?></textarea><br /><br /><br />
<input type="submit" name="submit" value="Submit">
</form>

Ergens in je bestand een .php validatiebestand requiren

<?php require '../includes/input.php'; ?>


Dan daar (in input.php) bijvoorbeeld




function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if (empty($_POST["comment"])) {
$commentErr = "Een bericht typen is noodzakelijk";
} else {
$comment = test_input($_POST["comment"]);
}


en ook bij input.php de variabele wel definieren (als zijnde leeg en aan het begin van input.php)


$comment = "";


Eerst is dan de variabele leeg en zie je hem niet, na de submit blijft het staan wat je in hebt getypt.

En je kan het ook in $_SESSION opslaan als je wil, of zelfs in een database. Maar ik heb het zelf op deze manier gedaan


Ik denk dat de topicstarter op zoek is naar een oplossing in (puur) JavaScript (dit topic staat in het JavaScript subforum).

Het kan wel, al is dit niet echt het juiste / makkelijkste middel om dit doel te bereiken. Het zou inderdaad een stuk makkelijker zijn als je gebruik maakt van een server side scriptingtaal zoals bijvoorbeeld PHP.

Daarnaast:
<?php
function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>

I don't know about this one though :/. strip_slashes() is alleen nodig als magic_quotes_gpc aan staat. Bij htmlspecialchars() is het handig/verstandig om deze te voorzien van meer parameters (de juiste flags -parameter 2- en een specifieke character encoding -parameter 3-). Ik weet niet waar je deze bovenstaande alles-in-een functie vandaan getrokken hebt of dat je deze zelf verzonnen hebt?

Reageren