change Jquery fires all inputs of the same name

0

Hello

I added a change event of jQuery in the input field with date-picker, so in every change already make the change in the DB. However, this input field is repeated for each user with the same name.

The code is working normally, it makes the changes right and saved in the database for each user separately. However, when I look at the log I see that it fires for all registered users (even though it does not affect the others, only it has been modified).

$("input[name='last-day-training']").on('change', function() {
		var id = $(this).attr('alt');
		var last_day_training = $(this).val();
		var data = {'key':'last-day-training','last_day':last_day_training,'user':id};
		data = JSON.stringify(data);
			$.ajax({
				type : 'POST',
				url : 'funcoes/_planejamento.php',
				dataType : 'json',
				data : {data:data},
				success: function(data){
					console.log(data);
					if(data.sql=='ok'){
					}else{
						alert('Erro, por favor contate o administrador');
					};
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					console.log(XMLHttpRequest);
					console.log(textStatus);
					console.log(errorThrown);
				}
			});
	});
<input name="last-day-training" alt="<?php echo $l->id;?>" type="text" data-date-format="dd-mm-yyyy" data-date-viewmode="years" class="form-control date-picker">
    
asked by anonymous 01.03.2016 / 14:37

0 answers