Jump to content

how to perform these fileds are required - unless submit button is disabled

Recommended Posts

I've form consisting of multiple fileds and I need to disable sumit button unless user fill smth in those fileds. I've smth like this

 $(document).ready(function() {        $("#submit").attr('disabled', 'disabled');     $("#eventName").keyup(function(){    // treba prerobit        if($(this).val() != '') {     $("#myText").keyup(function(){          if($(this).val() != '') {if (document.getElementById("start").value() !=""){ // mozno tiez (function){

but this is not dong the work. wouldn't be smth like while(1) and chcek if every filed is filled - wtih some timer ?

Link to post
Share on other sites

You should have 1 function that will check every field, so it would just get the value of every field and return false if any of them are empty, or else return true. Then you can put a keyup handler on each invidiual field to call that one function to test everything.

Link to post
Share on other sites

I've find this on Stackoverflow - and it works fine

 $('#submit').attr('disabled', true);$('.required').keyup(function () {   var disable = false;       $('.required').each(function(){ //type hidden exclude            if($(this).val()==""){  //notifikovat ze nefunguje GPS - adresa                  disable = true;                  }       });                                      // tato funckia check text filedy ci su filled   $('#submit').prop('disabled', disable);                                });    
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...