0
As you can see in my example below, I have a form that plays the data written in the entries (input
) html and these are stored in localStorage.
In the input=date
i need the date provided to be transformed into a countdown (countdown
), for the remaining days.
<form id="form">
<label>Name:</label> <input type="text" id="name"><br>
<label>Deadline:</label> <input type="date" id="deadline"><br>
<label>Image:</label> <input type="file" id="pic">
<input id="create" type="button" value="Create" />
</form>
<div id="tbody"></div>
<script>
$(function(){
$('#create').click(function () {
var theName = $('#name').val();
var theDeadline = $('#deadline').val();
var pic = document.getElementById("pic").files[0];
var imgUrl;
var reader = new FileReader();
reader.onload = function(e) {
var imgURL = reader.result;
$('#tbody').prepend("<div>" + theName + "<br>" + theDeadline + "<br><img src=" + imgURL + "></div>");
var tbody = $('#tbody').html();
localStorage.setItem('tbody', tbody);
saveDataToLocalStorage(imgURL);
}
reader.readAsDataURL(pic);
return false;
});
$('#tbody').html(localStorage.getItem('tbody'));
return false;
});
</script>
example version in jsfiddle: https://jsfiddle.net/7qtk9gyh/
I really liked the puglin jquery.countdown.js, It’s very simple, however, as I’m new to scripts, I don’t even know how to make it work from an input and combined with the form. Any help is very welcome!
Friend, I have difficulty in how to implement what happened to me, I am very new in this. You could pass me the example in fiddle?
– Thiago Soubra
I created that fiddle with the implementation in your code. I have removed all code that is not pertinent to date logic. I suggest you do this to simplify your future questions, leaving only exemplified what really needs help.
– leocabrallce
First of all, thank you very much. I thought it was important to make the example more complete so that they understand better how the context works. For example. I need the counter to be created in conjunction with the functioning of the form. In your solution I can’t "take" Countdown together with the other variables - there when I write elements by .prepend. and use the values dynamically (e.g.: "<a>" + varX +"</a>") -, because it is very necessary that it is possible to create more than one Countdown, one at each click on "create" as well as everything else, and not just replace it.
– Thiago Soubra
I think it would be necessary to have only one storage in the localStorage, which is the whole, "tbody" of the example. Unfortunately I don’t have enough knowledge to try to do this on my own :(
– Thiago Soubra
@Thiagosoubra, I created more that fiddle containing some implementations that may come to help you, including the full rescue of the Torage site. For anything else, I suggest you raise separate questions like "how to save HTML in localStorage", "how to count the difference between dates". I hope I’ve helped.
– leocabrallce
@Thiagosoubra, you made it?
– leocabrallce
Sorry for the delay, I ended up having to devote myself to studies. I still could not really test, but what you gave me is great and well explained
– Thiago Soubra
Thank you very much!!
– Thiago Soubra