disable submit button until file selected for upload

后端 未结 5 806
名媛妹妹
名媛妹妹 2020-12-08 10:30

I have a form for uploading images. I\'d like to disable the submit button, until user selects an image to upload. I\'d like to do it with jQuery. Currently I have a JavaScr

5条回答
  •  心在旅途
    2020-12-08 11:25

    Instead of disabling the submit, is it potentially more helpful to offer instruction if the user presses it without selecting a file first? So add something like this as the onclick code of the submit?

    var bFileEmpty = !document.getElementById('filControl').value; if (bFileEmpty) alert('Please select a file'); return !bFileEmpty;
    

    Note that your file control will need an ID as well as a name

提交回复
热议问题