Is there a way in PHP to show the number of files selected from an "input = file" inside the input? something like that.
I saw only code which Print the number in a label outside the input, such as (from this question)
$ ('input [type = file]'). Change (function () {fileCount = this files.length; $ (this) .prev () .text (filecount + 'selected');})
but I can not understand How am I able to put in the input ... inside the "value" can be?
This is my input code
& lt; Div id = "file-ins-immagini" & gt; & Lt; Div class = "at-form-in" & gt; AggiGi Iginese & lt; / Div & gt; & Lt; Input type = "file" name = "file-input []" id = "file-input" value = "" class = "file" multiple & gt; & Lt; / Div & gt;
Thanks!
It is very easy to use plain javascript, or jQuery:
/ * Input files calculation * / $ ("body") ("Change", function () {var numFiles = $ ("input", [0] .files.length; $ ('.phpfile'). Adclass ('active'); // optional for optional CSS}};
The above code creates a function that calculates whatever you choose from the form button. With jQuery Styling Elements (CSS / Mouseover Effects) Allows a little more creativity, but is not necessary
Code-js lang-js prettyprint-override "> / * Input files calculation * / $ (" body "). [0] .files.length; $ ('.php files') AddClass ('Active');}) / / mouseover effects * / $ ('.php files'). Mouseover (function ($ (this) .addClass ('over');}). Mouseout (function () { $ (This) .removeClass ('over');});
/ #wrapper {width : 600px; Margin-left: auto; Margin-right: auto; } .browseTitle {font-family: Helvetica Neue; Font-size: 14px; Art color; Padding: 8px 6px 8px 6px; Width: 610px; Swim left; _float: none; Background: # aaa; Boundary-radius: 5px; Border: 2px solid #FFFFFF; Cursor: indicator; } .browseFiles {font-family: menlo; Font-size: 11px; Padding: 2px 2px 2px 2px; Width: 620px; Swim left; _float: none; Background: #ddd; Boundary-radius: 5px; Cursor: indicator; } .on {background: # 77a509; }. At {background: #eee; }. Active {background: # 9ad60c; }. Button, input, {font-family: inherit; Font-size: 100%; }. Button {status: inline; Padding: 5px; Font: bold 1.2em sans-serif; Background: None; Cursor: indicator; }. Button: hover. Button: Focus {framework: none; Background: # 9ad60c; Color: # 000; Boundary-radius: 5px; Border: 1px; }
& lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.11.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Div id = "wrapper" & gt; & Lt; Div class = "browseTitle" & gt; Imaginee aligate & lt; / Div & gt; & Lt; Div class = "browsefiles" & gt; & Lt; Form enctype = "multipart / form-data" class = "button" & gt; & Lt; Input type = "file" name = "upload file []" multiple = "multiple" /> & Lt; / Form & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Comments
Post a Comment