This piece of code is somehow not working and I dont know why, im not good at php nor js just trying to make some website.
The part that is not working is this favorite button, it works like it has to work but it does not switch to "unfavorite" after click, it only works if u refresh the browser.
This is the html that is generated by the php file:
<a class="btn" id="fav28" title="Add to Favorites" href="javascript:;" onclick="AddFav('28','fav','add')">
<i class="icon-heart"></i>
</a>
And this is the js function:
function AddFav(id, dothis, dowhat) {
$.ajax({
url: ("/process.php?do="+dothis+"&id="+id+"&action="+dowhat)
});
if(dowhat == "add"){
document.getElementById(dothis+id).className = 'disabled';
document.getElementById(dothis+id).onclick = another_function
document.getElementById(dothis+id).title = 'Remove from Favorites';
}else if(dowhat == "remove"){
document.getElementById(dothis+id).className = 'btn';
document.getElementById(dothis+id).title = 'Add to Favorites';
}
}
I have tried the
document.getElementById(dothis+id).onClick = "AddFav(28,id,remove)";
but nothing happens with this, it simply does not change the onclick
what it has to do is to change the "onclick" event from
onclick="AddFav('28','fav','add')"
to
onclick="AddFav('28','fav','remove')"
Thanks in advance.