<!DOCTYPE html>
<html>
<head>
<style>
form {
display: inline-block;
}
form input[type=text],
form textarea {
float:right;
}
form textarea {
height:100px;
width:450px;
}
p {
overflow:hidden;
}
</style>
<script>
function download(filename, text)
{
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
</script>
</head>
<body>
Introduce un texto que se descargara de un archivo de texto
<form onsubmit="download(this['name'].value, this['text'].value)">
Nombre del archivo de texto: <input type="text" name="name" value="test.txt">
<p>Contenido:<br><textarea name="text"></textarea></p>
<p><input type="submit" value="Descargar archivo de texto"></p>
</form>
</body>
</html>