Hi,
I have a problem with some JavaScript code, i have three fields in my form scoreActuel, addedScore and NewScore, i used the onChange function because I want that every time the fields addedScore is updated , the field NewScore is updated as the sum of the values of the fields addedScore and scoreActuel, I hope I was clear
Below my source code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<script >
function changeTest ( form ) {
form.nv_scor.value = form.score.value + document.getElementById("sub_cat").value; }
</script>
</head>
<form class="form-horizontal" action="updateChauf2.php?id=<?php echo $id?>& score= <?php echo $score?>" method="post">
<div class="control-group">
<label>addedScore</label>
<select name="sub_cat" id="sub_cat"></select>
</div>
<!--score-->
<div class="control-group">
<label for="score">scoreActuel</label>
<div >
<?php
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT score FROM personnel WHERE id = {$id} ";
$q = $pdo->prepare($sql);
$q->execute();
$data = $q->fetchAll(PDO::FETCH_ASSOC);
Database::disconnect();
?>
<!--<select size=1 name="score" id="score">
<option name="score" id="score" value="">--scoreActuel --</option>-->
<?php foreach($data as $value): ?>
<input readonly name="score" id="score" onchange="changeTest(this.form)" type="text" value="<?php echo $value['score'] ?>">
<?php endforeach; ?>
</div>
</div>
<!--score-->
<div class="control-group">
<label for="nv_scor">NewScore</label>
<select name="nv_scor" id="nv_scor"></select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">update</button>
<a class="btn" href="chaufAffect.php">back</a>
</div>
</form>
</body>
</html>
My problem is that when the field addedScore is updated, the field NewScore is not updated, so the function changeTest does'nt work, i hope that someone could help me, thanks