Onclick值以显示在另一个输出中

问题描述 投票:0回答:1

单击下拉列表中的值时出现问题。它应该应该自动显示我的体重(总计)。

enter image description here有人可以帮助我,如何默认情况下从“标记分配”下拉列表中自动调用该值作为权重(总计)。

商标分配代码:

<div class="form-row">
  <label>Marks Allocation (%):</label>
  <select name="percentage" class="form-control" oninput="this.className = ''">
    <?php 
    $sql = mysqli_query($connection,"SELECT * FROM continous_assess"); 
    while ($row=mysqli_fetch_array($sql))
    { ?>

    <option value="">
      <?php echo $row['percentage']; ?>
    </option>
    <?php 
    }
    ?>
  </select>
</div>

重量代码:

<div class="form-group">
  <label>Weightage</label>
  <input type="number" name="first" class="prc" />
  <input type="number" name="second" class="prc" />
  <input type="number" name="third" class="prc" />
  <input type="number" name="fourth" class="prc" />
  <input type="number" name="fifth" class="prc" />
  <label>Total</label>
  <output value="<?php echo $row['percentage'];?>"></output>
</div>
javascript php forms echo
1个回答
0
投票

这应该对您有帮助;

<script type="text/javascript">
function updateVal() {
    // Get value
    var val = document.getElementById("percentage").value;

    // Set value
    document.getElementById("exampleInput").value = val;    
}
</script>

<select name="percentage" id="percentage" onchange="updateVal()">
    <option value="">- Select something -</option>
    <option value="example1">Example 1</option>
    <option value="example2">Example 2</option>
    <option value="example3">Example 3</option>
</select>

<input type="text" name="exampleInput" id="exampleInput">
© www.soinside.com 2019 - 2024. All rights reserved.