iDec
iDec

Reputation: 727

Change button link after click

I have a <button> element inside a <form> that has onsubmit='return false' so if I try to link the button inside an <a> tag it won't be called. Right now if you click that button it will execute an animation, and since onsubmit returns false the page isn't reloaded, but I want that same button to open https://google.com i.e. after it has been clicked once, I've tried adding the attributes method=GET action=google.com to the form using JQuery once the button is clicked but it opens google on the first click, not in the second one. Any ideas?

<form class="box" id="box" onsubmit="return false">
  <button class="sign-button">Submit</button>
</form>

Upvotes: 2

Views: 1498

Answers (2)

krillgar
krillgar

Reputation: 12815

This will have to be done in JavaScript. In the example below I've used jQuery to make it simpler.

var checkedAlready = false;

$('.box button.sign-button').click(function () {
    if (!checkedAlready) {
        // Do animation...
        checkedAlready = true;
    } else {
        location.href = "http://google.com";
    }
});

Upvotes: 1

micahblu
micahblu

Reputation: 5212

A simple location.href="http://google.com"; should do the trick

Upvotes: 1

Related Questions