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

151
Visualizações
MathJS parse values from input field

I'm trying to parse some values like x^2 and x from an input field, then dividing them using mathjs

This is my JS

function LDivide() {
            ldft = document.getElementById("LD1").value;
            ldst = document.getElementById("LD2").value;

            var LDans = math.simplify(math.parse(ldft / ldst));
            document.getElementById("LDansBox").innerHTML = LDans;
            document.getElementById("LDansBox").style.display = "inline"
        }

html as follows. I'd put x^2 in the first field and x in the second, for example, in order to get x as an answer because x^2/x = x

<input type="text" id="LD1" placeholder="First Term"> | <input type="text" id="LD2" placeholder="Second Term"><br>
<button id="LDSubmit" class="btn btn-success" onclick="LDivide()">=</button><br>
<p class="ansBox" id="LDansBox"></p>

It simply says NaN.

I've tried searching for a solution to no success.

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