The HTML drop-down menu keeps the selected value after submission without returning to the default value

Time:2019-11-8

Copy code

The code is as follows:

<html>
<body>
<?php
//Get select value
$select_value = isset($_GET[‘select’]) ? $_GET[‘select’] : ”;
?>
<form action=”?”>
<select name=”select”>
<option value=””>default</option>
<option value=”option1″ <?php
//If the value obtained above is the same as the value in this option,
//Print selected, so that the option is selected by default
echo $select_value == ‘option1’ ? ‘selected’ : ”
?>>option1</option>
</select>
<input type=”submit” value=”submit” />
</form>
</body>
</html>

This script should be added to each option. If there are more than one option, you can print in cycles.

Recommended Today

The use of progressbarcontrol, a progress bar control of devexpress – Taking ZedGraph as an example to add curve progress

scene WinForm control – devexpress18 download installation registration and use in vs: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243 When using ZedGraph to add curves, the number of curves is slower if there are many cases. So in the process of adding curve, the progress needs to be displayed, and the effect is as follows     Note: Blog home page:https://blog.csdn.net/badao_liumang_qizhi […]