0

So I have this jQuery script but when you click the button it doesn't go along with what its supposed to.

I'm using the same script on a different button and it works.

Cant seem to find the issue D:

jQuery Script:

<script type="text/javascript">
$(document).ready(function(){
    $("#stop").click(function() {
        var host = $("host").val();
        if(host != ""){
            $("#bootres").html("<p class='box'><img src='http://urgentbooter.com/img/ajax-loader.gif' border='0' alt='' /> Stopping attack...</p>");
            $.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){
        } else {
            alert("The host field must contain the IP to the attack you want to stop!");
            $("#host").focus();
        }
    });
});
</script>

Button Code:

<button type="button" id="stop" class="button red">Stop Attacks</button>

By the way the other button it works for is nearly the same code and its on the same page.

Let me know if more information is needed!

4
  • I put right after the click event handler and before the var host line "alert('Test');" and it didn't work when you click the button, if that helps at all. Commented Jan 27, 2014 at 5:55
  • just a tip: try to see what errors are in your console. It will tell you a lot about this kind of mistakes! The answer of felix will solve the problem i think! Commented Jan 27, 2014 at 5:56
  • It shows on line 98 there is an unexpected token else, which is where it says else { alert("The host field".... etc.. Commented Jan 27, 2014 at 5:58
  • That tells me that the problem is located before the else statement: see my answer below. Commented Jan 27, 2014 at 6:06

3 Answers 3

3

you open the function here :

$.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){

this function is empty and not closed before the else keyword

Sign up to request clarification or add additional context in comments.

Comments

3

Try to change:

var host = $("host").val();

to:

var host = $("#host").val();

You forgot to give # for targeting id here.

4 Comments

@user3023566 can you post the relevant HTML markup here? Currently you only show the button code.
Would you like me to make a jsFiddle?
Yes, it's even better :)
What does your console say?
1

Problem was with your code alignment.

Check your if block .

Try this code :

$(document).ready(function(){
    $("#stop").click(function() {
        var host = $("#host").val();
        if(host != ""){
            $("#bootres").html("<p class='box'><img src='http://urgentbooter.com/img/ajax-loader.gif' border='0' alt='' /> Stopping attack...</p>");
            $.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){
            } );}

                   else {
            alert("The host field must contain the IP to the attack you want to stop!");
            $("#host").focus();
        }
    });
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.