I have been using a script I found somewhere on this site, perhaps in the Tutorials, but I have not rediscovered it here, yet.
I have used it as an alternative way to warn a user if the information they are about to enter has already been reported in another form already saved. Then they can skip wasting time filling out the fields only to find out they have basically duplicated an earlier form.
The script uses some div code next to or under the key field that will launch the ajax search of a table when this field is filled in.
Then an external php script named check_requests.php I create sitting in the include/ folder takes that key field value, searches the assigned table, and if it finds data then it will send back the result as simply "Exists".
[size="3"]On the form page itself in the Javascript OnLoad Event code the first line var message I want to read something like "The following records were found for this client assigned to this Sales person: Joan Armstrong, February 12, 2014 and Frank Wright, March 25, 2014"[/size]
The existing javascript that works for simply saying 'Yes or No' sits looking like this:
var message = "A matching record already exists in this table.";
var ctrlSap = Runner.getControl(pageid, 'sap');
ctrlSap.on('change', function(e) {
if (this.getValue()=='') {
$('#avoid-duplicate').css('display','none');
}
else {
$.get("check_requests.php", { sap: this.getValue()}).done( function(data){
if (data=='exists') {
if (message!='') $('#avoid-duplicate').html(message);
$('#avoid-duplicate').css('display','block');
}
else {
$('#avoid-duplicate').css('display','none');
}
})
}
});
What I need for this current project is to find all records that match in another table outside of the one using this form. Before the form is submitted a pop up window inside an html div in the form html code quickly displays if it finds records in another table that match this key field value.
The Key field in the form field & for the search function in my php script is the account number of this client.
What I want to do is instead of showing a static message if duplicates are found in another table is to pop up a display of each record's fields that I pulled from the Search query in my php script.
<?php
include("include/dbcommon.php");
$rs = CustomQuery("select reqid, sap,trainerid, trainername, senddate from requests2014 where sap = '" .db_addslashes($_GET['sap']) . "'");
while ($data =(db_fetch_array($rs)))
{
$reqid=$data["reqid"];
$sap=$data["sap"];
$trainerid=$data["trainerid"];
$trainername=$data["trainername"];
$senddate=$data["senddate"] ;
}
echo "exists";
{
echo ""; }
?>
The users want this so they will know what other sales people by name and date in 2014 were previously assigned to this client.
I looked at setProxy values and things like that and different combined php and javascript examples but I cannot yet make a visible display popup after a known duplicated account number is filled into the form.
Does someone have a successful project where they have passed a form value entered before the form is submitted that launches an Ajax search and passes back the found values to a Var message window?
Thank you for your kind help!