tags:

views:

32

answers:

2

i have an ajax function(with arguments) and i want to call it via html

the calling now is:

<a href='javascript:;' class='vote_down' id='$wordNum'></a>

and the ajax function starts with:

$("a.vote_down").click(function(args){

how do i add the arguments to the html code

A: 

Generally the way you do that is to get the value of an HTML element in your click handler:

$("a.vote_down").click(function(){
    var arg1 = $("#argument1").val(); // Gets the argument from the value of an element
    var art2 = $("#argument2").text(); // Gets the argument from the text of an element

    // Do some fancy stuff
});
Pat
my question is how do i send the args from the html call
@nisnis84: Just add `callAjaxFunction(arg1, arg2)` to the anonymous function.
Felix Kling
add it to the html code?
A: 
<a href="#" onclick="javascript:functionName(arg1, arg2);">

Point of note: it's always a good idea to also provide an alternative for those with JavaScript disabled. For example, in your href attribute you could link to a page that has a normal HTML form to submit the vote.

Martin Bean