- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › jQuery – Auto Refresh Page
Hello,
I’m writing some code for a postcode calculation, what I want to happen is instead of hitting submit to calculate the distances I want JQuery / Ajax to do this automatically when the text box changes…
Below is the code I have currently got, is there an easy way to inject so Ajax into this?
// Connect to the database server
$dbcnx = mysql_connect("", "", "");
if (!$dbcnx) {
echo( "
Unable to connect to the " .
"database server at this time (this is a host connect problem).
" );
exit();
}
// Select the database
if (! mysql_select_db("", $dbcnx) ) {
echo( "
Unable to locate the " .
"database at this time(this is a dbconnect problem).
" );
exit();
}
function calc_postcode_seperation($pcodeA,$pcodeB)
{
// PCODE A
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='{$_POST}' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[0]=$row[Grid_N];
$gride[0]=$row[Grid_E];
// PCODE B
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='{$_POST}' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[1]=$row[Grid_N];
$gride[1]=$row[Grid_E];
// TAKE GRID REFS FROM EACH OTHER.
$distance_n=$gridn[0]-$gridn[1];
$distance_e=$gride[0]-$gride[1];
// CALCULATE THE DISTANCE BETWEEN THE TWO POINTS
$hypot=sqrt(($distance_n*$distance_n)+($distance_e*$distance_e));
$text.= round($hypot/799,0);
return $text;
}
?>
Thanks,
Scott