I have a script that enables my uses to block / unblock users. They're both in the same function 'blockToggle(type, user, button)' and depending on the type( either block or unblock) it executes that script. But what I'm trying to do is if the current user doesnt have another user blocked, they can block them with the button, but when the user clicks the button, they have to refresh the page to unblock the user. I want the onclick attribute to change right away once the user clicks it without refreshing the page. Here are a few things i've tried:.
document.getElementById("blockBtn").onclick = "blockToggle('unblock', 'user', 'blockBtn')";
document.getElementById("blockBtn").setAttribute( "onClick", "javascript: blockToggle('unblock', 'user', 'blockBtn')";
document.getElementById("blockBtn").onclick = function(){ "blockToggle('unblock', 'user', 'blockBtn')"};
Neither one of these solutions worked for me. And I couldn't seem to find a solution from google search either. Is there anything I'm overseeing here? I'm sure the answers right in front of me.
unblock,user, andblockBtnsupposed to be literal strings or variable names? If they're variables, you shouldn't put them in quotes.