1

Iam trying to make some queries from database and trying to make filter from a map according to the country.

ive written the java script code and it works normaly and query php file as well. my problem just how to send a name with onclick function to start the query. the shown problem is always that the query variable is empty. the code as following :

<map name="Map" id="Map">
<area shape="poly" coords="948,4,454,927,452,932,454" value="USA" onclick="getCountry(this.value)" />

and javascript code which works fine:

function getCountry(value){

  $.post("search.php"
    , 
    {query:value},
    function(data) {
         $('#results').html(data);
      });

}

the variable query in search.php comes always back with error that it didnt recieved any data.

thank you in advanced

1 Answer 1

1

value is not a valid property for the area element so you can't use that. You could try title instead, which is a global attribute available to all HTML elements.

function bar(d){
  alert(d);
}
<div style='width: 50px; height: 50px; background: red;' title='FOO' onclick='bar(this.title)'></div>

Sign up to request clarification or add additional context in comments.

3 Comments

you mean make the map picture in the div which will forward the value inside the area ?
i have to make more than one onclick function because it is a world map.
No, I mean use title on your area elements to hold the value instead of value. The div here was only for example. Or you could simply use data-* attributes. developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/…*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.