简体   繁体   中英

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:

 <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?

    `

It is not possible. PHP script will never execute on onchange event. Don't confuse it with JavaScript. PHP scripts will only run on events like GET, POST, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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