Disable the submit button if no file is selected.

I am trying to disable the submit button when a file is not selected after a working solution on the Internet. Is this somehow related to the type of script?

Here is an example: disable the submit button until the file is selected for upload

<html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> $(document).ready( function(){ $('input:submit').attr('disabled',true); $('input:file').change( function(){ if ($(this).val()){ $('input:submit').removeAttr('disabled'); } else { $('input:submit').attr('disabled',true); } }); }); </script> </head> <body> <form action="#" method="post"> <input type="file" name="fileInput" id="fileInput" /> <input type="submit" value="submit" disabled /> </form> </body> </html> 
+4
source share
2 answers

Try declaring with jquery because jquery is not enabled:

  <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript"> $(document).ready( function(){ $('input:submit').attr('disabled',true); $('input:file').change( function(){ if ($(this).val()){ $('input:submit').removeAttr('disabled'); } else { $('input:submit').attr('disabled',true); } }); }); </script> </head> <body> <form action="#" method="post"> <input type="file" name="fileInput" id="fileInput" /> <input type="submit" value="submit" disabled /> </form> </body> </html> 
+2
source

Include jQuery library in <head>

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
0
source

Source: https://habr.com/ru/post/1484357/


All Articles