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

175
Visualizações
call js inside php not worked

I have issue with script js inside php so i want ipnut get the somme of the value return by function js in dispaly in input with condition in php inside the input in below my script php:

function getSum(){               
    let NotePresence= document.getElementById("NotePresence").value;
    let NoteValidation= document.getElementById("NoteValidation").value;
    let NoteEvaluation= document.getElementById("NoteEvaluation").value;
    let t=NotePresence+NoteValidation+NoteEvaluation;
    return t;
}

calling in php:

<div class="form-group" style="display: flex">
    <input readonly="" style='width: auto' type="text" 
            name="NoteFinale" id="NoteFinale" 
            class="form-control" maxlength="2" 
            value="<?php echo '<script type="text/javascript">getSum();</script>';?>
            size="4" />
    <label for="">&nbsp;/80</label>
</div>

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can't put a script element inside an attribute value.

If you want to assign a value to the attribute from JS, then:

  • Put the script somewhere after the element in the DOM
  • Find the element with DOM methods (e.g. document.getElementById)
  • Assign the value to the element with DOM

Note, however, that since you should know the initial values for the three elements you are reading from, you should be able to eliminate JS entirely and just do this with PHP.


$NotePresence = 50;
$NoteValidation = 100;
$NoteEvaluation = 150;

<input name="NotePresence" value="<?=htmlspecialchars($NotePresence)">
<input name="NoteValidation" value="<?=htmlspecialchars($NoteValidation)">
<input name="NotePresence" value="<?=htmlspecialchars($NotePresence)">
<input name="NoteFinale" value="<?=htmlspecialchars($NotePresence + $NoteValidation = $NoteEvaluation)">

That is, assuming you want to combine them when the document loads.

If you want to do it later, then…

In JavaScript you would need to move the code into a function that you call when a suitable event (e.g. change on an input or submit on a form occurs).

In PHP you would need to move the code to the place the data is submitted to and combine the data from $_POST.

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