0

I am working on google maps api where i have to calculate the distance from current location to user selected destination. The list of destinations are stored in javascript array as:

var details = [
    {
        'title': 'Sobo Central Mall',
        'address': 'PTMM Malvia Marg,Tardeo Road,Mumbai.',
        'lat': '18.975684',
        'lng': '72.811910',
        'open': 'NA',
        'close': 'NA',
        'sex': 'Unisex',
        'place': 'mall'
    }
    //and so on...
];

which I display in list:

for (i = 0; i < details.length; i++) {
    var place= details[i].title;
    var add= details[i].address;
    document.getElementById('list').innerHTML +='<p>'+ place+ '<br><div id="address"> ' + add +'</div></p><br/><hr/>';

here i want to call the another php i.e.direction.php file to which i can pass add variable

<a href="direction.php?add="+add+">dir</a>

And in direction.php:

<?php $add = $_GET['add'];?>
<script>
document.getElementById('desti').innerHTML = "<?php echo $add ?>";
</script>

But $add doesn't have any value in it. Can anyone sort out the error?or suggest any different way to pass the js variable to another php file.

Kevin Nagurski
  • 1,889
  • 11
  • 24
Dimple
  • 453
  • 9
  • 22

3 Answers3

0

add variable can't be call like this in html

So you have to use javascript to replace the url.

Give id to your anchor tag like this

<a id="myAnchor" href="direction.php?add=default_value">dir</a>

At the end when value is inserted in variable add then you write this

document.getElementById("myAnchor").href = "direction.php?add="+add;

Hope this will help

Aman Rawat
  • 2,625
  • 1
  • 25
  • 40
0

In html you should give a class instance name to a div (example: ajaxPostHandler) then in your javascript assign a click event to that div and fire a ajax post event (example: doAjaxPost())

$(".ajaxPostHandler).click(function(){
  doAjaxPost();
})  

function doAjaxPost(){
     $.post('direction.php',{
           add: add

        },function(response){
            if(response.success){
            }
            else{
            }
        });
   }

HTML

<div class="ajaxPostHandler">dir</div>
Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29
  • i don't have knowledge about ajax can u tell me how can i call ajax in anchor tag. or ajax will work on click? – Dimple May 21 '15 at 12:32
0

add in tag was getting null value Quotes problem:

<a href="direction.php?add='+add+'">dir</a>//single quotes for add

Dimple
  • 453
  • 9
  • 22