Steve Cronin
Steve Cronin

Reputation: 3

jQuery does not respond to button click (not submit)

I have one form on a page with no submit button:

 <form id='voteForm' action='xyz' method='post'>
 <fieldset>      
 <input type="hidden" id="task_id" value="{$feature_details['task_id']}" />
 <input type="hidden" id="vote_id" value="{$vote['vote_id']}" />
 <input type="hidden" id="vote_type" value="{$vote['vote_type']}" />
 <input type="hidden" id="vote_rating" value="{$vote['vote_rating']}" />
 <input id="btn-update-vote" class="btn btn-sm btn-primary" type='button' disabled="disabled" value="{L('SubmitVote')}">
 </fieldset>
 </form> 

I cannot get jQuery to trap a click event on the 'SubmitVote' button neither of these appear to work:

$('#btn_update_vote').click(function() { 
   console.log('Click: #btn_update_vote');
})  

$('form#voteForm').on('click', '#btn_update_vote', function() { 
   console.log('Click: #btn_add_comment');
})  

I do not understand what can cause this! Any help appreciated!

BTW: I CAN set the disabled attribute on the button using jQuery and on 'documentReady' I log the button to the console:

[Log] [ (tracker, line 446)
<input id=​"btn-update-vote" class=​"btn btn-sm btn-primary" type=​"button" disabled=​"disabled" value=​"Cast Your Vote">​
]

Upvotes: 0

Views: 223

Answers (2)

chiliNUT
chiliNUT

Reputation: 19592

<input id="btn-update-vote"

$('#btn_update_vote').click( //...

You declared your id with dashes (-), not underscores (_), so you need

$('#btn-update-vote').click(

Also @Richer is correct

Upvotes: 0

Richer
Richer

Reputation: 116

Your button attr disabled="disabled" make it unclickable, even inline onclick listen.

Upvotes: 1

Related Questions