简体   繁体   English

从下拉列表中将选定的值分配给PHP变量onchange,而无需按html表单中的“提交”按钮?

[英]Assigning a selected value from a dropdown list to a php variable onchange, without pressing submit button in a html form?

I have a html form and a dropdown list like this: 我有一个html表单和一个像这样的下拉列表:

 <form name="form1" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  <div>     
    <span>Select Event</span> 
    <select id = "events" onchange="run()" class = "pass" style="width: 209px">
    <?php while($row = oci_fetch_array($curs)):?>
    <option value="<?php echo $row[0];?>"><?php echo $row[1];?></option>
    <? endwhile; ?>
    <input type="submit" name="action" value="New Event"> 
    </select>               
    TextBox1<br>
    <input type="text" id="srt" placeholder="get value on option select"><br>   
</div>
</form>

I can successfully show the values that I take from the database table. 我可以成功显示从数据库表中获取的值。 And after that I want to use the selected value for another query which needs this selected value simultaneously without pressing submit button.And my run function is like: 之后,我想将选择的值用于另一个查询,该查询同时需要此选择的值而无需按下提交按钮。我的运行功能如下:

<script>
function run() {
    document.getElementById("srt").value = document.getElementById("events").value;
}

How can I assign this selected value to a php variable simultaneously? 如何同时将此选定值分配给php变量?

    `

It is not possible. 这不可能。 PHP script will never execute on onchange event. PHP脚本将永远不会在onchange事件上执行。 Don't confuse it with JavaScript. 不要将其与JavaScript混淆。 PHP scripts will only run on events like GET, POST, etc. PHP脚本将仅在GET,POST等事件上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM