<div class="form-group" style="text-align: right;">
<label for="city">Select No Rows Per Page</label>
<select class="form-control" name="selectrows" style="width: 70px; text-align: right;">
<option>25</option>
<option>50</option>
<option>100</option>
</select>
</div>
index.php
我想在选择选项上刷新index.php。
答案 0 :(得分:2)
如果您确实想这样做,则需要以某种方式将选定的选项添加到“重新加载”页面。您可以作为URL中的GET参数来执行此操作。因此添加:
<script>
document.addEventListener('DOMContentLoaded', () => {
document.getElementsByTagName('select')[0].addEventListener('change', (e) => {
location = 'index.php?selectrows=' + e.target.options[e.target.selectedIndex].value;
});
});
</script>
然后在PHP脚本中,您可以使用$_GET['selectrows']
答案 1 :(得分:0)
尝试以下代码。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function doReload(catid){
document.location = 'samepage.php?catid=' + catid;
/* But if you want to submit the form just comment above line and uncomment following lines*/
//document.frm1.action = 'samepage.php';
//document.frm1.method = 'post';
//document.frm1.submit();
}
</script>
</head>
<body>
<form name="frm1" id="frm1">
<select name="catid" id="catid" onChange="doReload(this.value);">
<option value="" selected="selected">---All Category---</option>
<option value="1">Category One</option>
<option value="2">Category Two</option>
</select>
</form>
</body>
</html>