0

i want to use jquery to retrieve a variable embedded in a html link, spo i can send it to the php file with jquery ajax. but i dont know how to do this.

this is what i have written:

    <script ...>
        $("a").click(function(){
             $.post("helpers/ajaxcall_country.php", {"HERE I WANT TO SEND THE VARIABLE"}, function(data){
                $("#countryselect").html(data);
            });
        });
    </script>


    while($row = mysqli_fetch_assoc($all_tags))
    {
        echo "<a id='" . $row['id'] . "' href=''>+</a>&nbsp;&nbsp;";
    }

it will be lets say 20 links ... all with different "id". i want to send this "id" value to php-file with ajax. any idea how to do it?

1
  • of course i will have document.ready first=) Commented Dec 3, 2009 at 18:26

1 Answer 1

3

try this:

<script ...>
    $("a").click(function(event){
         $.post("helpers/ajaxcall_country.php", {id: event.target.id}, function(data){
            $("#countryselect").html(data);
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

nice solution, Adding to this if url needed to be sent use event.target.href

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.