grey out submit button until form filled out

后端 未结 3 750
萌比男神i
萌比男神i 2021-02-09 02:23

I have the following form:

 
3条回答
  •  逝去的感伤
    2021-02-09 03:25

    Jquery would do that. On the .keyup event have jquery check if both field's lengths are > 0 and change the button to be disabled or not.

    $('#yourButton').button("disable");​​​​​​​​​​​​​
    
    $('.fields').bind('keyup', function() { 
    var nameLength = $("#sub_first_name").length;
    var emailLength = $("#sub_email").length;
    
    if (nameLength > 0 && emailLength > 0)
    {
       $('#yourButton').button("enable");​​​​​​​​​​​​​
    }
    
    } );
    

提交回复
热议问题