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

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

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 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