its related to the thread:http://w3schools.invisionzone.com/index.php?showtopic=50396
But i found that javascript related questions are better suited for this forum, rather then php.
var results = $('[name^=id]').map(function(){ var $this = $(this); var $defaultid = this.defaultValue; $($this).on('focusout',function(e){ var $id = $($this).val(); if ($id != $defaultid){ console.log($id); console.log($defaultid); $($this).css('background-color', '#FFA07A'); $.ajax ({ url: 'index.php?action=ticket_ajax', type: 'post', data: {'id': $id, 'defaultid': $defaultid, 'page' : 'update'}, success : function(data) { console.log(data); } }); }; }); });
Problem with the code above is that the ajax submits $id as default value, instead of the changed value.:{"id":"999","defaultid":"999"} is the json it returns to the console.Id should be 1 - the console.log right before the ajax prints 1 to the console.So why does ajax suddenly get a different value for it right after?