0

Есть три формы для выбора файлов, планируется загрузка на сервак ajaxом, mysqli insert_id (внесение информации о пользователе директории и новом имени файла в скуль), и подставление полученного insert_id в значение скрытого поля, для отправки на сервер целиком формы, но уже без обработки файлов.

                                        <div class="form-group">
                                            <label>Добавьте фото ТМЦ</label>
                                            <input type="file" class="form-control" name="wt_no_photo_add_file" id="wt_no_photo_add_file">
                                            <input type="hidden" name="wt_no_photo_add" id="wt_no_photo_add" value="">
                                        </div>
                                        <div class="form-group">
                                            <label>Добавьте скан гарантийного талона</label>
                                            <input type="file" class="form-control" name="wt_no_scangarant_add_file" id="wt_no_scangarant_add_file" >
                                            <input type="hidden" name="wt_no_scangarant_add" id="wt_no_scangarant_add" value="">
                                        </div>
                                        <div class="form-group">
                                            <label>Добавьте скан сертификата</label>
                                            <input type="file" class="form-control"  name="wt_no_certificate_add_file" id="wt_no_certificate_add_file">
                                            <input type="hidden" name="wt_no_certificate_add" id="wt_no_certificate_add" value="">
                                        </div>

Собственно вопрос, как мне узнать id или имя выбранной формы загрузки файла для внесения изменений согласно js коду ниже

 <script>
                                        $('input:file').on('change', function () {
                                            var data = new FormData();
                                            //Append files infos
                                            alert(this.name);
                                            jQuery.each($(this)[0].files, function(i, file) {
                                                data.append('file-'+i, file);
                                            });
                                            $.ajax({
                                                url: "ajaxupload.php",
                                                type: "POST",
                                                data: data,
                                                cache: false,
                                                processData: false,
                                                contentType: false,
                                                context: this,
                                                success: function (msg) {
                                                    if(msg)
                                                    {
                                                        tmp = msg.split('~');
                                                        if(tmp[0]==='success') {
                                                            document.getElementById(tmp[2]).value = tmp[1];
                                                        }
                                                        else if(tmp[0]==='danger') alert(tmp[1]);
                                                    }
                                                }
                                            });
                                        });
                                    </script>

P.S. Извиняюсь за гигантские отступы

1 ответ 1

0

Нашёл решение, оказалось простым

this.name

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.