There are various ways you can create AJAX call. The easiest is to use Javascript Framework like Mootools or JQuery. Ajax is simple this ways. Check http://demos111.mootools.net/Ajax.Form for Mootools demos and jquery here http://docs.jquery.com/Tutorials.
The logic is pretty simple. Add event to the text box to save the box once value changes. Your event function will generate Ajax request and send it to the server, receive response which you can use to let user know the status of save event, if you choose.
Here is quick thing I wrote for you, might help understand. Will need to include Mootools library. Might have bugs, but concept of Ajax call is there. page=index.php
<?php
// PHP before anything else...
//
// Check to see if task is specified and need to save changes
if (isset($_POST['task']) && $_POST['task'] == 'save') {
// mysql connection
$text = $_POST['name'];
// insert query
$isSuccess = 'Status of SAVING CHANGES';
// Output... output will be used by 'update' to set value of <div id="log">...</div>
// so user knows what is happening
echo $isSuccess ? 'Successfully Saved' : 'Failed to Save';
exit();
}
?>
<html>
<head>
<!-- NEED TO INCLUDE MOOTOOLS LIBRARY -->
<script type="text/javascript">
window.addEvent('domready', function(){
$('name').addEvent('blur', saveChanges);
/**
* Generates request and saves changes
*/
function saveChanges(){
// URL which will be called
var url = "index.php";
// New Ajex request. Note that it will be sent because of .request() at the end
new Ajax(url, {
// Method : post/get
method: 'post',
// Data to be passed
data :{
name : $('name').value,
task : 'save'
},
// Output of the AJAX will be set to this element
update: $('log')
}).request();
}
});
</script>
</head>
<body>
<form action="index.php" onsubmit="return false">
<div id="log"></div>
<!-- SOME CONTENT ... -->
<input type="text" name="name" id="name" value="">
</form>
</body>
</html>