What I want is perform some addition of values on dynamic input fields but its showing variable not found. Here is my form input field
<input type="text" name="test[]" placeholder="test" onchange=calculate();>
my javascript function
function calculate() {
var test = <?php echo json_encode($test); ?>;
alert(test);
console.log(test);
}
and I have a save.php file which insert data to MySQL
foreach($_POST['name'] as $key => $val) {
$proj = $_POST['project'][$key];
$test = $_POST['test'][$key];
$insert = "INSERT INTO test (name,project,test) values ('$val','$proj', '$test')";
$result = $conn->query($insert);
}