How do I use jQuery to disable a form's submit button until every required field has been filled?

前端 未结 6 1663
故里飘歌
故里飘歌 2021-01-01 08:21

I have a form with multiple inputs, select boxes, and a textarea. I would like to have the submit button be disabled until all of the fields that I designate as required are

6条回答
  •  抹茶落季
    2021-01-01 08:49

    An idea from me:

    • Define a variable -with global scope- and add the value true- Write a submit function within your check the value above varibale. Evalue the the submit event only, if the value is true.
    • Write a function which ckecks all value from input fields and select fields. Checking the length of value to zero. if the value length of one field zero then change the value of the global variable to false.
    • After that, add to all input fields the event 'onKeydown' or 'onKeyUp' and to all select boxes the event 'onChange'.

提交回复
热议问题