Masriyah
Masriyah

Reputation: 2505

Trouble calling javascript from href

I am having some trouble having my link function to execute javascript.

link:

<a class="glossyBtn" id="saveButton">Save</a>

Script:

<script type="text/javascript">
$(function (){
    $('form').submit(function () {
        $('#saveButton').attr('disabled', 'disabled');
    });
});
</script>

Upvotes: 1

Views: 173

Answers (1)

Tim
Tim

Reputation: 792

$('form').submit() is fired when you submit a form (usually with <button type="submit">). Your button is not of submit type.

You may achieve it adding the following onclick to your <a> element: onclick="$('form').sumbit();" or add the following to your JS code

$('#saveButton').click(function{
   $('#saveButton').attr('disabled', 'disabled');
   $('form').submit();
})

Upvotes: 2

Related Questions