Reputation: 2207
I have the following code when i add to the list it does not stay on the page when the browser is refreshed i am wondering is there a way around this.
<script language="javascript">
$('.example-default-value').each(function () {
var default_value = this.value;
$(this).focus(function () {
if (this.value == default_value) {
this.value = '';
}
});
$(this).blur(function () {
if (this.value == '') {
this.value = default_value;
}
});
});
function example_append() {
$('#step').append($('#example-textarea').val() + "<br />");
}
I would then like to be able to add to a list and have it stay on the list even after the page is reloaded.
Upvotes: 0
Views: 64
Reputation: 1390
You should save the items of your list somewhere in order to reload them when the page refreshes. You can do that either with an AJAX call or if you're using HTML5 you can opt to save it to browser's local storage.
Here is an example of how you can implement the AJAX call:
function example_append() {
$('#step').append($('#example-textarea').val() + "<br />");
$.ajax({ type: "POST", url: "somescript.php", data: "value=" + $('#example-textarea').val() });
}
Upvotes: 0
Reputation: 11264
Sorry but that is impossible, because when you refresh your page it will again parse your page from the server side script lets say php, and you are adding the elements simply by a clientside script javascript whose changes will be lost in your refresh..
You need to have them in your initial html...or body onload you can create those items that way they will be added your body =will be loaded..:)
Upvotes: 1