Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda