K
K
Kirill2016-01-16 01:34:31
PHP
Kirill, 2016-01-16 01:34:31

Saving text to input?

Hello! I have a question, I need to save the text entered by the user after pressing the save button in the input, here is the code

<textarea id="comment"></textarea>
<input type="text" id="fio">

<script>
var elements = document.querySelectorAll('input, textarea');

function checkValidity() {};

for (i=0; i<elements.length; i++) {
 (function(element) {
   var id = element.getAttribute('id');
   element.value = sessionStorage.getItem(id); // обязательно наличие у элементов id
   element.oninput = function() {
     sessionStorage.setItem(id, element.value);
     checkValidity();
   };
 })(elements[i]);
}
</script>

it works, but the input submit button disappears, more precisely the text in it is "Save", what did I do wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivanq, 2016-01-16
@quant78

https://jsfiddle.net/Ivanq/nzbk0a7z/4/

A
Alexander Aksentiev, 2016-01-16
@Sanasol

You interrupt all elements value, and that disappears.

A
Alexey S., 2016-01-16
@Winsik

<input type="submit" id="click"  value="Сохранить">

...
or vice versa, restore only the necessary id, and not all in a row

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question