newbieProgrammer
newbieProgrammer

Reputation: 3

How to save entered text in JS/Html

How do i save entered/ inputted text using JavaScript/ html.

What do I want: Name or code etc to be entered in a box (prompt box eksample) and then I want it to be displayed/ printed on the page and I want it to remain there so other people that visit can see it.

What I have: I have code that shows a prompt box where you can enter text then displays it in green. However what i want is for the entered text to remain on the website for others to see...

  function mobCode() {
mobCode = prompt("Insert Code", "Code here");
document.getElementById("mC").innerHTML = mobCode;
document.getElementById("mC").style.color="green";
}
<p id="mC"> Mob Code </p>
<button type="button" onclick="mobCode()"> Click to Add </button>

Upvotes: 0

Views: 408

Answers (2)

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 119

If you want to deal easier with persistence of the data, instead of setting up database and using server side script you can look at Facebook's Parse. The free plan is quite usefull for small projects. There is a JavaScript SDK that can be used directly from your javascript code.

Also you can view statistics from the Parse dashboard.

Here is some saple code for example:

// Create a new Parse object
var Post = new ParseObject("Post");
var post = new Post();

// Save it to Parse
post.save({"title": "Hello World"}).then(function(object) {
  alert("Yay! It worked!");
});

Upvotes: 0

dhershman
dhershman

Reputation: 341

What you will probably have to do is write a script that will send the entered input to a database you build which can store that information,and then have your js access the database to display it in a certain area of your page.

Check out this Q & A one of the answers is a nice article to help explain the idea behind it: Send data from javascript to a mysql database

Upvotes: 1

Related Questions