- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › fill the value of input file using jquery
Hi
i’m retrieving the user info of the databases {name, username, email, password, image_links}
the last field {image_links} contains the name and the type of the image , like (1_1.jpg) when the user wanted to update his profile the image will retrieve and place into an image element but the file input is still empty so when the user try to update his profile without changing his image the form will redirect back with an error telling that you should upload an image .
can we do something like
$(“input type=[file]”).attr(“value”,”image_link”);
or any thing like that …
can you guys show me a way to stop this error of showing .
i don’t know if you guys understand …
A bit more info would be great but I assume you’re looking for the .val
method.
$(“input type=[file]”).val(image_link)
That would be extremely useful, but at the same time, extremely dangerous. Due to security reasons, you cannot programmatically set the value of a file control.
An easy solution, however, is to create a hidden control or a variable in your javascript that contains the value of the filename and to use that value if the file control’s value is blank.
Note that if you are doing this via form submit, hidden controls will not get submitted with the form, so you will have to unhide the control immediately before the form gets submitted.
<input type="hidden" value="filename.ext" />;
<script>;
$(function () {
$("button").on("click", function (event) {
e.preventDefault();
$(".hidden-control").attr("type", "text");
$("form").submit();
});
});
</script>;