Solved

xajax javascript value

Posted on 2009-04-08
19
693 Views
Last Modified: 2013-12-13
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
Comment
Question by:ALASKASTREETMASTER
  • 10
  • 9
19 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103328
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103406
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103431
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103438
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103445
>> 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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103447
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103465
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103474
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103505
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:ALASKASTREETMASTER
ID: 24103544
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
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24103601
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103678
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103704
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103715
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103779
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103792
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24103834
thank you for everythying.  I will pick this up tomorrow. my wife is callimg me home.....
appreciate your help!
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24103845
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
 

Author Closing Comment

by:ALASKASTREETMASTER
ID: 31568325
thanks that got it. on to the next issue.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now