Home > Web Front-end > HTML Tutorial > HTML drop-down menu retains the selected value after submission without returning the default value

HTML drop-down menu retains the selected value after submission without returning the default value

高洛峰
Release: 2017-02-27 11:29:18
Original
2110 people have browsed it

This article mainly introduces how to retain the selected value without returning the default value after the HTML drop-down menu is submitted. Although the method is simple, it is more practical. Friends in need can refer to it

<html> 
<body> 
<?php 
// 获取select值 
$select_value = isset($_GET[&#39;select&#39;]) ? $_GET[&#39;select&#39;] : &#39;&#39;; 
?> 
<form action="?"> 
<select name="select"> 
<option value="">default</option> 
<option value="option1" <?php 
// 如果在上面获取的值和这个option里的值一样, 
// 就打印selected,让这个option默认被选中 
echo $select_value == &#39;option1&#39; ? &#39;selected&#39; : &#39;&#39; 
?>>option1</option> 
</select> 
<input type="submit" value="submit" /> 
</form> 
</body> 
</html>
Copy after login

Each option must be With this script, if there are multiple, you can print them in a loop.

For more html drop-down menus, after submission, the selected value is retained without returning to the default value. For related articles, please pay attention to the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template