'Clicking HTML Button and Create a File
Can someone helps me, i need to make a button when it Clicked, will creating a file in my storage
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<h1 style="color:green;">
Create Your First Account
</h1>
Name:<input type="text" id="username" value="Jack">
<p>
Password:<input type="password" id="password" value="some password">
</p>
<p>
<button type="button" onclick="createNow()">Create Your First Account</button>
</p>
<p href="admin_mode.html">
<button>Admin Mode</button>
</p>
<script>
var fs = require('fs')
function createNow() {
var userinput = document.getElementById("username").value;
var passwordinput = document.getElementById("password").value;
var content = `{ "username": "${userinput}, "password": "${passwordinput} "}`
//Create user acc
fs.writeFileSync(`./database/registeredUser/${userinput}.json`, content)
<a href="home.html">
}
</script>
</body>
</html>
i've put a fs.writeFileSync there and when someone click the button, its not creating the file and contents
Solution 1:[1]
You should use a.href="home.html"
function createNow() {
var userinput = document.getElementById("username").value;
var passwordinput = document.getElementById("password").value;
var content = `{ "username": "${userinput}, "password": "${passwordinput} "}`
//Create user acc
fs.writeFileSync(`./database/registeredUser/${userinput}.json`, content);
a.href="home.html";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shourov_return0 |
