1

I want to attach a function to my submit button. But my code doesn't seem to be calling the function.

Basically what I want it to do is, enabling all disabled field when the form is being submitted.

This below is my code:

<script>
function enableField() {
    $("#Booking_clientPackagedService_id").prop("disabled", false);
}
</script>


<?php
    echo CHtml::submitButton(Yii::t('app', 'Save'));
    $this->endWidget();
?>

This #Booking_clientPackagedService_id initially is disabled after certain action being done. But when I click on submit, I would like to enable the field. How can I do it? Please advise, thanks! :D

EDIT

So I've removed onclick event on my submit button and added as per Kancho Iliev's comment.

$( "#booking-form" ).submit(function() {
  $("#Booking_clientPackagedService_id").prop("disabled", false);
});

But it is still not working. Where have I missed out?

NewbieCoder
  • 676
  • 1
  • 9
  • 32

2 Answers2

2

Remove onclick event, and add

$("your_form_name").submit(function(){
   enableField();
}); 
Kancho Iliev
  • 701
  • 5
  • 13
0

This is the correct way of attaching a submit function:

$(function() {
    $("#formName").submit(function() {
        alert("hi");
        //do whatever 
    });
});
NewbieCoder
  • 676
  • 1
  • 9
  • 32