Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  79] [ 7]  / answers: 1 / hits: 24292  / 11 Years ago, sat, july 13, 2013, 12:00:00

I have the following JS / HTML code:



<input type=text class=file name=file_info id=file_info>
<div class=file_upload>
<input type=file id=file_upload onchange=name();>
</div>
<script>
function name() {
var fileName = document.getElementById(file_upload).value;
var fnSplit = fileName.split(/[/\]/);
fileName = fnSplit[fnSplit.length - 1];
document.getElementById('file_info').innerHTML = 'Fred Flinstone';
}
</script>


I want that after I upload file, the file-name will shown in the tput text, but this cide doesn't work.



How can I fix it?



Update : The file name should be inside the input text


More From » html

 Answers
14

Move your script element before the input element. You had better put the script element inside your head like this


Demo


Have update the answer!


[#77023] Thursday, July 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adam

Total Points: 363
Total Questions: 102
Total Answers: 104

Location: Burkina Faso
Member since Thu, Dec 15, 2022
1 Year ago
;