1
1
1010101010102015-04-04 16:30:42
JavaScript
101010101010, 2015-04-04 16:30:42

How to activate input file fields with click()?

Hello, I need to emulate clicking on an input file field using js.
Now I'm trying to figure out this solution.

$(function() {
            $("#formUploadBtn").click(function() {
                $("#formInput").click();
            });
        });

<form id="test_form" method="post" action="">
        <input type="file" id="formInput"/>
        <button id="formUploadBtn">Upload</button>
 </form>

when input enters the form group, the page is reloaded and nothing works. How to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Scriabin, 2015-04-04
@101010101010

e May the answer is simple - the button submits the form)
In order that there would be no submit

$(function () {
    $("#formUploadBtn").click(function () {
        $("#formInput").click();
        return false;
    });
    $('#formInput').change(function () {
        $('#test_form').submit();
    })
});

jsfiddle.net/mLgeLtgy

D
Dmitry, 2015-04-04
@thewind

focus () on the field did not try to put?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question