V
V
Valeriy19972015-09-11 12:21:25
JavaScript
Valeriy1997, 2015-09-11 12:21:25

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']);

                      });            



          }
}


To make it clear what I'm talking about, here is the full code: jsfiddle.net/t52ka/44

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arris, 2015-09-11
@Arris

are written in json

it's obviously being written into some kind of variable.
Catch the moment when the input is empty and reset the variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question