• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

xajax javascript value

I must be missing something.  I have tried all day and still can't find a way to pass a javascript variable to an xajax function in the same page. What am I missing?

Help!
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
 
function getll($longitude,$latitude){
//$lonquery=trim($formValues['longitude']);
//$latquery=trim($formValues['latitude']);
//$lonquery =  '-149.8375..-149.8373';
//$latquery =  '61.12851..61.12871';
$lonquery = $_GET['longitude'];
$latquery = $_GET['latitude'];
//$lonquery = $longitude;
//$latquery = $latitude;
 
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
 
 
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
<script>
x=0;
var taxid ;
var latitude = '61.12851..61.12871';
var longitude = '-149.8375..-149.8373';
<input type="text" size="24" name="longitude" value =  '-149.8375..-149.8373';>
</script>
 
</head>
<body>
<form name = "searchdist">
 <input type="text" size="24" name="latitude" value =  '61.12851..61.12871'>
<input type="text" size="24" name="longitude" value =  '-149.8375..-149.8373';>
<form/>
<div id="SomeElementId"></div>
 
<button onclick="xajax_getll($latitude = latitude,$longitude = longitude);">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
ALASKASTREETMASTER
Asked:
ALASKASTREETMASTER
  • 10
  • 9
1 Solution
 
Roger BaklundCommented:
There are some errors in your html. Try replacing it with the code below. To check that the lat/lon is transfered correctly, you can alert it like this:

$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid,lon=$longitude,lat=$latitude');");

<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
var latitude = '61.12851..61.12871';
var longitude = '-149.8375..-149.8373';
</script>
 
</head>
<body>
<form name = "searchdist">
 <input type="text" size="24" id="latitude" value =  '61.12851..61.12871' />
<input type="text" size="24" id="longitude" value =  '-149.8375..-149.8373' />
</form>
<div id="SomeElementId"></div>
 
<button onclick="xajax_getll(document.getElementById('latitude').value,document.getElementById('longitude').value);">test</button>
<button onclick="alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
ALASKASTREETMASTERAuthor Commented:
which lines do i use in the php xajax function?

//$lonquery=trim($formValues['longitude']);
//$latquery=trim($formValues['latitude']);
//$lonquery =  '-149.8375..-149.8373';
//$latquery =  '61.12851..61.12871';
//$lonquery = $_GET['longitude'];
//$latquery = $_GET['latitude'];
//$lonquery = $longitude;
//$latquery = $latitude;
0
 
ALASKASTREETMASTERAuthor Commented:
I have variables defined in the script before calling the xajax getll(). Can I call the variables instead of the form fields? seems like an extra st
ep to write the variables to the fields then retireve them.

i appreciate your help!
thank god for guru's!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Roger BaklundCommented:
None of them, the parameters are transfered in the function call. They are defined here:

function getll($longitude,$latitude){

... and they are set here:

<button onclick="xajax_getll(document.getElementById('latitude').value,document.getElementById('longitude').value);">test</button>

"document.getElementById('latitude').value" fetches the value from the element with id=latitude.
0
 
Roger BaklundCommented:
>> I have variables defined in the script before calling the xajax getll(). Can I call the variables instead of the form fields?

Yes, if latitude and longitude are javascript variables, you can do like this:

<button onclick="xajax_getll(latitude,longitude);">test</button>
0
 
ALASKASTREETMASTERAuthor Commented:
ok,  so how does the transfrred value get to :
$findCommand->addFindCriterion('LONNUM',$lonquery);


//$lonquery=trim($formValues['longitude']);
//$latquery=trim($formValues['latitude']);
//$lonquery =  '-149.8375..-149.8373';
//$latquery =  '61.12851..61.12871';
$lonquery = $_GET['longitude'];
$latquery = $_GET['latitude'];
//$lonquery = $longitude;
//$latquery = $latitude;

require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
0
 
Roger BaklundCommented:
The function definition also defines the input parameters:

function getll($longitude,$latitude){

...you can use them like this:

$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
0
 
ALASKASTREETMASTERAuthor Commented:
it still hangs up!
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
 
function getll(){
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
 
 
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
var latitude = '61.12851..61.12871';
var longitude = '-149.8375..-149.8373';
</script>
 
</head>
<body>
<form name = "searchdist">
 <input type="text" size="24" id="latitude" value =  '61.12851..61.12871' />
<input type="text" size="24" id="longitude" value =  '-149.8375..-149.8373' />
</form>
<div id="SomeElementId"></div>
 
<button onclick="xajax_getll(document.getElementById('latitude').value,document.getElementById('longitude').value);">test</button>
<button onclick="alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
Roger BaklundCommented:
Now you have removed the parameters from line 13:

function getll(){

...it should be like this:

function getll($longitude,$latitude){

Except from that I can't see anything wrong.
0
 
ALASKASTREETMASTERAuthor Commented:
still hangs up.  Sorry, I must still  be missing something.
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
 
function getll($longitude,$latitude){
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
 
 
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
var latitude = '61.12851..61.12871';
var longitude = '-149.8375..-149.8373';
</script>
 
</head>
<body>
<form name = "searchdist">
 <input type="text" size="24" id="latitude" value =  '61.12851..61.12871' />
<input type="text" size="24" id="longitude" value =  '-149.8375..-149.8373' />
</form>
<div id="SomeElementId"></div>
 
<button onclick="xajax_getll(document.getElementById('latitude').value,document.getElementById('longitude').value);">test</button>
<button onclick="alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
Roger BaklundCommented:
It works for me. I don't have your Filemaker db, so I commented it out. Try doing the same, to elliminate the possibility of an error in that part of the code.
function getll($longitude,$latitude){
/*
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
*/ 
$taxid = 123;
$row = 246;
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}

Open in new window

0
 
ALASKASTREETMASTERAuthor Commented:
still get taxid undefined? works if i comment out my fm stuff. and include the taxid and row variable you put in.
<?php
require_once('xajax/xajax_core/xajax.inc.php');
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
function getll($longitude,$latitude){
 
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
$result = $findCommand->execute();
$records = $result->getRecor3ds();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
//$taxid = 123;
//$row = 246;
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
?>
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
var latitude = '61.12851..61.12871';
var longitude = '-149.8375..-149.8373';
</script>
 
</head>
<body>
<form name = "searchdist">
 <input type="text" size="24" id="latitude" value =  '61.12851..61.12871' />
<input type="text" size="24" id="longitude" value =  '-149.8375..-149.8373' />
</form>
<div id="SomeElementId"></div>
 
<button onclick="xajax_getll(document.getElementById('latitude').value,document.getElementById('longitude').value);">test</button>
<button onclick="alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
Roger BaklundCommented:
What value do you get for $row? if it is 0 (zero), it means the loop is not executed, i.e. no rows are found for these criteria in the db.
0
 
ALASKASTREETMASTERAuthor Commented:
i dont get no values back.  just "undefined" nothing on the test button , just whirls for a second then stops.  Click on the  alert button and says 'undefined"
0
 
ALASKASTREETMASTERAuthor Commented:
this works
http://www.streetmaster-ak.com/products/webimages/axajaxtest.php

code below
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
 
function getll(){
$lonquery =  '-149.8375..-149.8373';
$latquery =  '61.12851..61.12871';
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
 
$taxid = $record->getField('TAXID_11');
$lat = $record->getField('LATNUM');
$lon =  $record->getField('LONNUM');
$row++;
}
 
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse;
 
}
 
 
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid ;
</script>
 
</head><body>
 
<div id="SomeElementId"></div>
<button onclick="xajax_getll();">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
Roger BaklundCommented:
You said it worked if you commented out the filemaker stuff, and hardcode values for $row and $taxid? If so, the problem is obviously with the filemaker stuff. Create a separate test script with the filemaker stuff, and make sure that part works, before you move it back into the xajax script.
0
 
ALASKASTREETMASTERAuthor Commented:
thank you for everythying.  I will pick this up tomorrow. my wife is callimg me home.....
appreciate your help!
0
 
Roger BaklundCommented:
Then this should work also:
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
 
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
 
$xajax->registerFunction("getll");
 
$xajax->processRequest();
 
function getll($longitude,$latitude){
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$findCommand =& $fm->newFindCommand('ASMLATLON');
$findCommand->addFindCriterion('LONNUM',$longitude);
$findCommand->addFindCriterion('LATNUM',$latitude);
$result = $findCommand->execute();
$records = $result->getRecords();
 
$row = 0;
 
foreach ($records as $record) {
  $taxid = $record->getField('TAXID_11');
  $lat = $record->getField('LATNUM');
  $lon =  $record->getField('LONNUM');
  $row++;
} 
 
$objResponse = new xajaxResponse();
$objResponse->script("row=$row;taxid = $taxid;alert('row=$row;taxid = $taxid');");
return $objResponse; 
}
 
?>
 
<html><head><title>Xajax test</title>
<?php $xajax->printJavascript(); ?>
<script type="text/javascript">
x=0;
var taxid;
var longitude =  '-149.8375..-149.8373';
var latitude = '61.12851..61.12871';
</script>
 
</head><body>
 
<div id="SomeElementId"></div>
<button onclick="xajax_getll(longitude,latitude);">test</button>
<button onclick="javascript:alert(taxid)">alert</button>
 
</body>
</html>

Open in new window

0
 
ALASKASTREETMASTERAuthor Commented:
thanks that got it. on to the next issue.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now