Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!