0

I have a html form. I want to store form data in another txt file using javascript. For ex: I have a html form and store-data.txt file . when user fill the form and hit submit, so data stored in store-data.txt file. How I will do this using javascript.

3
  • There are many working examples in the web with direct links to codepen etc. Have you checked them? Commented Sep 25, 2021 at 12:26
  • codepen.io/Ev1ltw1n/pen/PojyaLz Are you looking for this? Commented Sep 25, 2021 at 12:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Oct 3, 2021 at 10:54

3 Answers 3

1

Javascript can`t save data on server. JS can save data on clients machine. Data on clients machine can be stored using cookie. But I feel, it isnt an aim. Store data from froms can server side apps, driven like php.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use filesaver.js library for a clean implementation or follow along with this codepen It is the quickest.

1 Comment

Stackoverflow have snippet that make it easier to have codepen. I suggest you to include it in your question
0

if you wanted to store input values assign all values in an object then JSON.stringify then throw it to this function to get text file of json

function createTextFile(str){
    var file = new Blob([str])
        anchor = document.createElement("a")
    anchor.href = URL.createObjectURL(file)
    anchor.download = "fileName"
    anchor.click()
    URL.revokeObjectURL(anchor.href)
    anchor.remove()    
}

var input = "this is a string to test"
createTextFile(input)

and if you wanted to save in server side with php there is function in php file-put-contents

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.