invikeavaxibe
New Member
I have \[code\]<input type="file" id="file" onchange="filename();" /> <div id='filename'></div>\[/code\]The function goes something like this\[code\]function filename() {var input = document.getElementById("file");if (filename == null) { document.getElementById("filename").innerHTML = ""; return false;}var lastIndex = filename.lastIndexOf("\\");if (lastIndex >= 0) { filename = filename.substring(lastIndex + 1);}document.getElementById("filename").innerHTML = "The filename is: "+filename+".";}\[/code\]My code is similar to the above, and works fine, but when clicking on choose file, then choosing a file, the filename is shown. After that, if I click choose file, then hit cancel. Now the file is not loaded anymore, but the text that says the filename is still there. Is there a code I can use that will automatically listen to the file field all the time, and when the file value is empty it will change the filename?I want to do this using JavaScript or jQuery.EDIT\[code\]$("document").ready(function(){ $("#file").change(function() { alert('changed'); });});\[/code\]This will detect new images selected and when the file selection window is exited (when pressing cancel) the file's name attr. is changed to "", which is what I wanted.