1

I am selecting input values from the database and I want to send it to the javascript function myFunction(). I have tried it but the value fetched from database is not been passed to the function of JavaScript.

PHP codes*

<select name="" id="mySelect" class="form-control" onchange="myFunction()" style="height: 40px;font-weight: 70px">
<?php
$query = "SELECT * FROM academic_level";
$select_posts = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($select_posts))
{
$idacademic_level = $row['idacademic_level'];
$title = $row['title'];
$amount_added = $row['amount_added'];
echo "<option value='{$title}'>{$title}</option>";
}

?>

</select>

JavaScript codes

<script type="text/javascript">
function myFunction() { 
var t = "<?php echo $idacademic_level; ?>";
if (document.getElementById("mySelect").value == t)
{
     var amount_added = "<?php echo $amount_added; ?>";
  var  u = 10 + amount_added;
  document.getElementById("price").value =  +u;
}
}
</script>
dominic tanui
  • 21
  • 1
  • 8

0 Answers0