<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
link
rel
=
'stylesheet'
href
=
<
link
rel
=
"stylesheet"
href
=
<
style
>
h1,
p {
text-align: center;
}
.container>div{
margin-top: 25px;
}
</
style
>
</
head
>
<
body
>
<
div
class
=
"container"
>
<
h1
class
=
"is-size-2 has-text-success"
>
GeeksforGeeks
</
h1
>
<
p
><
b
>Bulma File with JavaScript</
b
></
p
>
<
div
id
=
"file-with-js"
class
=
"file has-name is-centered is-link"
>
<
label
class
=
"file-label"
>
<
input
class
=
"file-input"
type
=
"file"
name
=
"selected-image"
>
<
span
class
=
"file-cta"
>
<
span
class
=
"file-icon"
>
<
i
class
=
"fas fa-upload"
></
i
>
</
span
>
<
span
class
=
"file-label"
>
Select an Image..
</
span
>
</
span
>
<
span
class
=
"file-name"
>
No Image Selected
</
span
>
</
label
>
</
div
>
</
div
>
<
script
>
// Select the input element using
// document.querySelector
var input = document.querySelector(
"#file-with-js>.file-label>.file-input"
);
// Bind an listener to onChange event of the input
input.onchange = function () {
if(input.files.length > 0){
var fileNameContainer =
document.querySelector(
"#file-with-js>.file-label>.file-name"
);
// set the inner text of fileNameContainer
// to the name of the file
fileNameContainer.textContent =
input.files[0].name;
}
}
</
script
>
</
body
>
</
html
>