I am creating a very simple project and need to save the two entries in a txt file separated by a comma locally in the folder where the html is. I need to do it through Javascript but I can not. Can anyone help me?
My html code:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TESTE</title>
<link rel="stylesheet" type="text/css" href="./css/main.css">
<script src="js/main.js"></script>
</head>
<body>
<header class="menu-principal">
<main>
<div class="cabecalho">
<div class="logo">
<img src="./img/logo.png">
</div>
</div>
</main>
</header>
<form action="#" class="formulario" name="formulario">
<div class="formulario__grupo">
<label class="formulario__label" for="cod">Código</label><br>
<input class="formulario__campo" type="text" id="codid" placeholder="Insira o código" required="required" name="cod" />
</div>
<div class="formulario__grupo">
<label class="formulario__label" for="desc">Descrição</label><br>
<textarea class="formulario__campo" name="desc" id="descid" cols="30" rows="10" placeholder="Insira uma descrição.." required></textarea>
</div>
<div>
<button onclick="Enviar()" class="formulario__botao">Salvar</button>
</div>
</form>
</body>
</html>
I'm just doing a test myself by opening the page of a folder, but I need to know how I can save it to a txt file after clicking the save button. I wanted to do this for js but I do not know how.
My JS:
function Enviar() {
var cod = formulario.cod.value;
var desc = formulario.desc.value;
if (cod ==""){
alert('Preencha o campo CÓDIGO');
formulario.nome.focus();
return false;
}
else if (desc ==""){
alert('Preencha o campo DESCRIÇÃO');
formulario.nome.focus();
return false;
}
else{
alert('os seus dados foram encaminhados com sucesso');
// AQUI EU QUERO CHAMAR UMA FUNÇÃO QUE GERE E SALVE O TXT NA PASTA DO HTML;
}
}