Upload File - Customizing Html - javascript

How can I do to browse my files when i click in a button "Upload" ?
I need to create a hidden file input?
More Explain:
I can't edit css of input type file of my html forms. So in each browser I have a different layout. I don't want it. I want to customize my form.
I created a button. When I click on the button, I want to appear the file selection screen.
When I select the file and press ok , I want to put the path string of my file in the input that I created.

Could you provide more information? You need to use the file html form element.
The file element lets you browse your local documents naturally.
To process the file attachment you need to know a programming language like php

I solved my problem with this code:
<div class="input-append">
<label for="showpath">File Upload:</label>
<input id="showpath" type="text" onclick ="javascript:document.getElementById('CommentFile').click();"/>
<button type="button" onclick ="javascript:document.getElementById('CommentFile').click();"></button>
<input type="file" name="data[Comment][file]" id="CommentFile" style='visibility: hidden;' onchange="updateInput(this.value,'showpath')"/>
</div>

<input type='file' />
More info at w3schools.

Related

File Upload Issue in HTML

Once I upload a file through input type, it then gets disabled, can't upload another file until the page is refreshed. I don't want to upload multiple files at once, but one after the other. Then click on submit.
My code:
<i class="fa fa-video-camera"></i>
<span>
<input type="file" id="video-dancing" name="postVideo" accept="video/*">
</span>
https://daveismyname.com/upload-multiple-files-with-a-single-input-with-html-5-and-php-bp
hope this would help your problem .
Once the first upload is complete, simply add code to refresh the page.
use attribute multiple to select multiple files.
<input type="file" id="video-dancing" name="postVideo" accept="video/*" multiple >

how to set upload button in dropzone.js

I am using dropzone.js as per my requirement.
I want to use div as file upload control like when user drag & drop a file in the div it should show uploaded files and when user click "submit" button , it should go to server, next other stuff.
But here I am facing problem like, with Form only it is working, when i am uploading a file it is directly going to server with file, i have written like
<form action="~/Employer/GetFile" method="post" enctype="multipart/form-data" class="dropzone" id="dropzoneForm" style="width: 50px; background: none; border: none;">
<div class="fallback">
<input name="file" type="file" />
<input type="submit" value="Upload" />
</div>
</form> // Working Fine ,
<div class="watermark pull-left margin-top-1 dropzone" id="divDropFile"></div> // Not wroking,
it should upload file(s) only like dropzone.js without destination urls, it should go to server when click on file upload button only. Moreover, file drop is not working.
Please help me anyone.. if it is not possible without form submit, please give any suggestion for alternative solution.
I am not on my development computer so I can't try it out, but there are two things that might help.
1) The div that you want to serve as the dropzone hot spot should not have the class dropzone. It needs the class dz-message. Write it like this:
<div class="watermark pull-left margin-top-1 dz-message" id="divDropFile" data-dz-message></div>
2) If you don't want it to automatically send the file to the server, you need to add autoProcessQueue = false in your Dropzone.options object. You will then need to manually call myDropzone.processQueue() later to upload the files.

To change the default text "No File Selected" of a browser button with some other text in JSP

I have a file browser button in my jsp. It has a text like "No File Selected" beside it at the very beginning. after selecting the file, it shows the file path instead of "No File Selected". Now I want to replace "No File Selected" with ".jpg" or the supported format names.
Is it possible to do so?
my code for the browser button..
<form:input name="file1" type="file" accept="image/png,image/jpeg"
id="files" path="" size="500" title="files" />
Use this style...
in order for you to make a design of you input file..
do not display the input.. just hide it and make a design on your button or whatever element you want. Just like my example below..
<input type="file" id="myUpload" style="display:none" />
<button type="button" onclick="javascript:document.getElementById('myUpload').click();">Upload Photo</button>
I hid the input while displaying the button and giving it an attribute onclick and letting the javascript do the magic..
here is the example:
http://jsfiddle.net/aYd72/
and better use bootstrap for better designs
I hope it will help you

Display text "loading..." after file is selected in input type="file" element

I am using a really simple form to allow users to upload files to my server. It works well, but i have noticed that even for very small files, right after selecting the file to upload, it takes a while (2-3 sec) to change the "No file selected" to the actual name of the file selected. (Actually it says it in spanish - guess somebody knows where i am).
The thing is that during this loading time the mouse wheel nor the browser look like they are thinking, so im afraid the user wont be patient enough and will feel its not working.
So i just want to display a text saying, "hey, hold on - its loading" And this is what i have tried with no luck:
A.
<input type="file" name="userf" onload="function(e){e.innerHTML='Loading';};">
</input>
B.
<input type="file" name="userf" onchange="function(e){e.innerHTML='Loading';};">
</input>
C.
<input type="file" name="userf" onload="function(){this.innerHTML='Loading';};">
</input>
D.
<input type="file" name="userf" onchange="function(){this.innerHTML='Loading';}">
</input>
If this is not possible, could i not just change the default message: "No file selected"?
EDIT
If possible, no JQuery, just javascript
You cannot change the default text on an input file element. But you can do some work arounds in order to get something similar you want. It may require jQuery or other framework to do the job.
This post may help: How to change the button text of <input type="file" />?

Automatically submitting a form when an upload file is chosen

I have a HTML page with the following input tag:
...
<input type="file" id="browseContactImageButton" />
...
Clicking the button on the page results in Open File Dialog. If I want to do the actual uploading, I need another button to click (submit), because this input file button is used just to provide the path to the file.
Is it possible to click the browse button, select the file and to start the uploading function immediately after the file has been chosen? If yes, could anyone provide the code snippet? Thanks.
If you want the form to submit after the user has made their selection, then simply add
<input type="file" onchange="this.form.submit();" ..... >
I had the same requirement.
I figured out to use onchange event of fileupload control to fire c# method.
But I'm getting FileUpload1.HasFile property always 'False' and file name was not set yet.
My markup:
<asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode="AutoID"
ViewStateMode="Enabled" onchange="UploadImage();"/>
any suggessions?

Categories