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?

2 Answers 2

2

Remove onclick event, and add

$("your_form_name").submit(function(){
   enableField();
}); 
Sign up to request clarification or add additional context in comments.

Comments

0

This is the correct way of attaching a submit function:

$(function() {
    $("#formName").submit(function() {
        alert("hi");
        //do whatever 
    });
});

Comments

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.