Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
Setting input image default value

I want to set input tag default value to "http://websamplenow.com/30/userprofile/images/avatar.jpg"

background-image is useless.. I am using django and bootstrap.

My template.

{% extends 'base.html' %}

{% block content %}
<style>
textarea.form-control {
  height: 500%;
}
</style>

<div class="container" style="padding-top: 60px;">
    <h1 class="page-header">Edit Profile</h1>
    <div class="row">
        <form class="form-horizontal" method="post" enctype="multipart/form-data">
            {% csrf_token %}
        <!-- left column -->
            <div class="col-md-2 hidden-xs">
                <img id="image" class="img-responsive img-thumbnail" />
                <input name="image" id="files" type="file" class="text-center well-xs">
            </div>

        <!-- edit form column -->
            <div class="col-md-8 col-sm-6 col-xs-12 personal-info">
                <div class="form-group">
                    <label class="col-md-3 control-label"></label>
                    <div class="col-md-8">
                        <button class="btn btn-primary" type="submit">submit</button>
                        <span></span>
                        <a class="btn btn-default" href="{% url 'soldier-list' %}">&nbsp;&nbsp;cancel&nbsp;&nbsp;</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<script>
	document.getElementById("files").onchange = function () {
    var reader = new FileReader();
    reader.onload = function (e) {
        // get loaded data and render thumbnail.
        document.getElementById("image").src = e.target.result;
    };
    // read the image file as a data URL.
    reader.readAsDataURL(this.files[0]);
};
</script>
{% endblock %}

Please help me. Thanks.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can't, for security reasons. If you could, you could create invisible file inputs on the page and assign them default values and possibly upload images unknowingly from the client.

Check out this answer on stackoverflow: How to set a value to a file input in HTML?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!