JSFiddle - React, Tailwind, and code Playground

http://stackoverflow.com/questions/12826793/detecting-file-selection-jquery

by RASG

HTML

<table border="0" style="width:100%">
    <tbody>
        <tr>
            <td style="width:50%">
                <input id="preview" type="button" value="Preview" />
            </td>
            <td>
                <input type="button" id="save" value="Save" />
            </td>
        </tr>
        <tr>
            <td style="width:50%">Upload (JPEG Only):</td>
            <td>
                <form id="uploadForm" class="upload" method="POST" enctype="multipart/form-data"
                action="/path/to/file.php?action=preview">
                    <input type="file" name="file" id="file" />
                    <input type="submit" id="uploadSubmit" style="display:none" />
                    <div id="hiddenFields">
                        <!-- JQUERY -->
                    </div>
                </form>
            </td>
        </tr>
    </tbody>
</table>

JavaScript

$("#file").on('change', function(e) {
    type = "upload"
    submitChanges("preview")
    $(this).val('')
})

function submitChanges(myvar) {
    alert(myvar)
}