David Willis
David Willis

Reputation: 717

Can someone explain this javascript function?

I have this javascript function I am trying to understand. I don't know if it has been implemented in jquery.

It is a function that is related to a button. When the button is clicked on it should display on the screen that vote has been cast. Can you explain to me the purpose of 'id' and 'nb' in this function and what each line does. I presume the fourth line takes the user to vote_yes.php of the base url if they click on the button? $lang189 is a variable saying vote collected and output between the literal braces is html and javacript, with code outside the braces php.

  {literal}
    function VOTEYES(id,nb) {
        $('#vote'+id).css('display','none');
        $.post("{/literal}{$baseurl}/vote_yes.php{literal}",{"id":id,"nb":nb},function(html) {
            $('#vote'+id).html('{/literal}{$lang189}{literal} ('+html+')').fadeIn();
        });
    }{/literal}

I am familar with PHP not no javascript experience.. I don't want to learn the whole language to understand how this vote button works, please help. Cookies are involved.

Thanks.

Upvotes: 0

Views: 233

Answers (5)

Juan Zamora
Juan Zamora

Reputation: 386

Will send id and nb to vote_yes.php. response output will be on (html) variable. now with $('#vote'+id).html(xxx) will set that the response received will be content of another html element.

Upvotes: 0

DOK
DOK

Reputation: 32851

I believe the first line inside the function hides the button so the user can't click it again.

Upvotes: 0

Aaron Hathaway
Aaron Hathaway

Reputation: 4315

Yes, it is using jQuery. It appears that the id is being used to determine which element with the id of voteID to use. I'm not quite sure what the nb is used for because it is simply passed as a POST variable to the vote_yes.php page in the AJAX. I would investigate that page for more info.

Upvotes: 0

meder omuraliev
meder omuraliev

Reputation: 186742

  1. A function VOTEYES is defined that takes 2 arguments id and nb
  2. It finds an element with an ID of 'vote'+id, so if id was 2 it would be vote2
  3. It hides that element making it non-clickable.
  4. It does an ajax request, POST call to whatever $baseurl, the root domain I suppose, is and appends vote_yes.php to it
  5. It passes the id and nb parameters in the POST request.
  6. Then it takes the html from that vote_yes.php page and appends it to the vote2 element by fading it in.

Upvotes: 2

Justin Niessner
Justin Niessner

Reputation: 245489

The function is simply making a call to a page with the URL:

{/literal}{$baseurl}/vote_yes.php{literal}

And passing in the following parameters via "POST":

"id": id
"nb": nb

and using jQuery to fade in the response from the page.

Upvotes: 0

Related Questions