Answer the question
In order to leave comments, you need to log in
Why does writing data to json not work correctly?
Upon successful entry of body numbers into the input, the input data (body number and date ) are written to json . But if you delete the input and enter the number there again, then the data will be written twice. That is, with each removal of the number, the data will be written more and more times. I can't find the error. Tell me how to fix the situation?
Here is the code:
function checkValid() {
var val = $("#phone").val();
var enable = true;
var valid = false;
if (!val || val.replace(/\D/g, '').length < 12){ enable = false;}
if (codes[val.substr(5, 3)]){ valid = true;}
if (!enable || !valid) {
$('.error').text('Некорректный ввод');
$("#call").attr("disabled","disabled");
}else{
$('.error').text('');
}
if (enable && valid) { $("#call").removeAttr("disabled");
var retite = new Date();
$('#call').click(function(){
obj = {
dates: 'дата',
time: 'время',
phone: phone
};
obj['date'] = retite
alert(obj['date']);
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question