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

204
Vistas
How to extract the returne value of my function JavaScript

I used this function to get the ratio width/height of a photo to assign automatic values of portrait or lanscape:

    var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    return divi.value;
}
alert(divi)

Will return the correct value, but I want to in corporate this code:

if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200");
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}

I tried someting like this:

var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200"); //nump is the number of repetitions the While loop as been in (for increments)
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}
}

But the values of if and else won't output... They do if I put them out of the first function. This is all in a While loop, so the divi variable will change everytime.

Can someone help me get that Divi value for my If condition? Thank you!

about 4 years ago · Juan Pablo Isaza
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