Teererai Marange
Teererai Marange

Reputation: 2132

Jquery: input type=submit still submits even when disabled

I have a submit button that I am trying to disable programmatically but for some reason, when I change the disabled attribute of the element, I can still click submit and the event code still fires.

As an example, I have the following element in my html:

<input name="reg_submit" id="reg_button" value="Buddy" class="reg_button reg_button_new crm_submit" type="submit">

and have the following in my script to disable it:

var k = jQuery.noConflict();
k('#reg_button').attr("disabled", true);

And when I print debug, the element is in fact disabled. Is my approach flawed?

Upvotes: 3

Views: 122

Answers (1)

Jedi
Jedi

Reputation: 3348

You can try to set the disabled property.

var k = jQuery.noConflict();
k('#reg_button').prop("disabled", true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="reg_submit" id="reg_button" value="Buddy" class="reg_button reg_button_new crm_submit" type="submit">

Upvotes: 1

Related Questions