1

I have a button that I have tied to some JS that is disabling the button and changing the text to 'Loading...' once clicked, then the APIs go to work(around 12-15 seconds). However when I click the button it just says 'Loading..' and the form doesn't submit, to clarify nothing is happening besides the button changing. Preferably I'd like to use 'input' but with that the form submits but the button doesn't change. I am no JS expert so any help is great. Thanks.

<button id="fat-btn" class="btn btn-xs btn-primary btn-block">Get Quotes</button>




    <script>
        $(function(){
            var $btn = $('#fat-btn');
            $btn.click(function(){
                var $this = $(this);
                $this.attr('disabled', 'disabled').html("Loading...");
                setTimeout(function () {
                    $this.removeAttr('disabled').html('Get Quotes');
                }, 3000)
                document.getElementById("fat-btn").submit();
            });
        })
    </script>
2
  • is your button inside form tag ? Commented Dec 9, 2013 at 20:09
  • yes, its definitely within the tags. Commented Dec 9, 2013 at 20:21

1 Answer 1

7

You need to use the ID of the form to submit. Not the id of the button.

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

8 Comments

he hasn't forms because button submits without javascript
besides, dom object itself don't have submit() method
Wouldn't that defeat the purpose of what I'm doing here? Seems like if I did that then the button would no longer change to the 'Loading...' state.
Not if the button is outside of the form or you stop the default event from occurring.
This question is right. If you want to submit the form, you need to target the form. When you are submitting the form, the page reloads. You will not see the button change because the page is submitting and it will be set to what the next page has set. That is how form submissions work.
|

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.