0

First of all, I'm trying to use an HTML element (button) to, onClick, perform a JavaScript function I have. The function is called Unban(player) which "unbans" a player from something I'm working on.

The element looks like this,

<button name="button" id="button" onclick="Unban('somebody')"/>

And the JavaScript looks like this:

function Unban(player){
    if (confirm("Are you sure you want to remove the ban on " + player + "?")){
        $.post("actions/unban.php",{Player:player},function(result){
            if (result.contains("Error:"){
                alert(result);
            }

            else{
               alert("You have unbanned " + player + "!");
            }
});

    }

}

The problem is: Nothing happens at all when I call upon the Unban(player) function. I've done a bit of tests and it runs properly without the $.post, so it must be something related to it.

The PHP file works fine and is functional. It is also properly referenced in $.post.

2
  • Are you sure you have jQuery sourced? Are you getting any console error messages? Commented Apr 10, 2013 at 12:48
  • Also, slightly OT, but its best to separate your javascript... instead of the onclick, you could have a descriptive id such as unbanButton, then bind your code to a click event on that button id. Commented Apr 10, 2013 at 12:51

1 Answer 1

3

There is a syntax error. A ) is missing here

if (result.contains("Error:")){
                alert(result);
 }
Sign up to request clarification or add additional context in comments.

Comments

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.