Validate file size and type in a multiple input

后端 未结 1 1106
暖寄归人
暖寄归人 2021-01-28 13:52

i have 3 input file, i wanna make a javascript validation for 3 input file in one submit button form event onSubmit=\"\"

相关标签:
1条回答
  • 2021-01-28 14:02

    Change type of submit button to normal button and use onclick handler for it by giving a id as upload,

    <form action="step2_crud_dev.php" method="post" enctype="multipart/form-data" class="form-horizontal" role="form" id="dataPribadi"  >
        <div>
            <input type="file" name="fUpload1" id="fileUpload1"/>
            <input type="file" name="fUpload2" id="fileUpload2"/>
            <input type="file" name="fUpload3" id="fileUpload3"/>
        </div>
        <div>
            <input type="button" id="upload" value="upload" />
        </div>
    </form>
    

    and your click event handler should be,

    $(document).ready(function(){
        $('#upload').click(function(){
            alert('hello');
            $('input[type="file"]').each(function(){
                var thisFile = $(this);
                var fileSize = thisFile[0].files[0].size;
                alert(fileSize);
            });
            $('form#dataPribadi').submit();
        });
    });
    

    UPDATED FIDDLE

    0 讨论(0)
提交回复
热议问题