I think I have this right now...
Firstly, make sure the Ajax libraries are included in your file.
For your main PHP file, you need to have the following javascript/Ajax included:
<script>
function add_source_reference()
{
$.ajax({
type: "POST",
data: {
source_ref: $('#source_ref').val(),
},
url: "gl_validation_checks.php",
success: function(data)
{
if(data === 'SOURCEREF_EXISTS')
{
$('#sourceref_res')
.css('color', 'red')
.html("This reference already exists");
}
}
})
}
</script>
You need to add an OnExit command to a text field (the "source_ref" field), where this equals "add_source_reference()"
Create a new PHP file called gl_validation_checks.php for example:
<?php
$source_ref = mysql_real_escape_string($_POST['source_ref']);
$sql = "SELECT source_ref FROM bank_trans WHERE source_ref='".$source_ref."'";
$query = mysql_query($sql);
if(mysql_num_rows($query) == 0)
{
echo('NO_SOURCEREF');
}
else
{
echo('SOURCEREF_EXISTS');
}
?>
Make sure you include:
<span id="sourceref_res"></span>
Including this will indicate where the message will show if there is a duplicate.
I hope this all makes sense.