Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Position of an element with Javascript for a suggest research box

I am trying to make a suggest research box like Google. I am not doing the server side with Ajax for the moment because I have a problem with my code. As you can see on the picture, the position of the suggestion box is not correct.

Positionement problem with JS

Here is the code :

  var values = ["Chatelet", "Gare de Lyon", "Orsay-Ville"];


function positionner() {
var suggest = document.getElementById("suggestion");
var champ = document.getElementById("fmsearch");
suggest.style.left = getLeft(champ) + "px";
suggest.style.top = (getTop(champ) + champ.offsetHeight) + "px";
}

function getLeft(element) {
var offsetLeft = 0;
while (element != null) {
offsetLeft += element.offsetLeft;
element = element.offsetParent;
}
return offsetLeft;
}
function getTop(element) {
var offsetTop = 0;
while (element != null) {
offsetTop += element.offsetTop;
element = element.offsetParent;
}
return offsetTop;
}
positionner();




function suggerer() 
{
  var suggest = document.getElementById("suggestion");
  suggest.innerHTML = "";
  var i, ele;
  for (i=0 ; i<values.length ; i++)
  {
    ele = document.createElement("div");
    ele.innerHTML = values[i];
    suggest.appendChild(ele);
  }
  suggest.style.display = "block";
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda