Basically I need to Set the input placeholder to last value typed into input after 1 second has passed. The reason is that if the user once again deletes everything from it, the placeholder will now show the last value typed into input after last autoupdate AJAX call AND NOT the placeholder value loaded during original page load.
WORKING CODE
function autoSave(client_id, project_id, mainsheet_id, t_id, t_val) {
if (t_val != '') {
// Refresh variables just in case.
client_id = $('#CLIENT_ID').val();
project_id = $('#PROJECT_ID').val();
mainsheet_id = $('#MAINSHEET_ID').val();
// AJAX POST request to run MySQL UPDATE query on this database field ( WTRESRVD ).
$.ajax({
url: "processor.php",
method: "GET",
data: {
postCLIENT_ID: client_id,
postPROJECT_ID: project_id,
postMAINSHEET_ID: mainsheet_id,
postT_ID: t_id,
postT_VAL: t_val
},
dataType: "text",
beforeSend: function() {
// setting a timeout
$('#status').text('Please wait...');
},
success: function(data) {
// If data return after a successful request isn't an empty string..
// ADD SERVER RESPONSE HANDING HERE.
/* Status Codes
return 0 = Nothing to Update
return 1 = Successful Update Query
return 2 = Database Connection refused
return 3 = MySQL Query Error OR Wrong URL Parameters */
// If data return 0 = Nothing to Update
if (data == '0') {
$('#status').text("Status: Nothing changed. Nothing saved.").show();
// ..fadeOut over 3 seconds.
$('#status').fadeOut(5000);
}
// If data return 1 = Successful Update Query
if (data == '1') {
// Create variable time to reference later.
var time = showTime();
// Update div status with last saved time stamp then..
$('#status').text("Status: Saved @ " + time).show();
// ..fadeOut over 3 seconds.
$('#status').fadeOut(5000);
}
// return 2 = Database Connection refused
if (data == '2') {
$('#status').text("Status: Database Connection refused.").show();
// ..fadeOut over 3 seconds.
$('#status').fadeOut(5000);
}
// return 3 = MySQL Query Error OR Wrong URL Parameters
if (data == '3') {
$('#status').text("Status: MySQL Query Error OR Wrong URL Parameters.").show();
// ..fadeOut over 3 seconds.
$('#status').fadeOut(5000);
}
}
});
} else {
// like this maybe???
// not working...
$(t_val).attr("placeholder", t_val);
}
}