我的代码如下:
<h1>Sort by</h1>
<form>
<select name='myfield' onchange='this.form.submit()'>
<option value="Relevance">Relevance</option>
<option value="Date">Date Posted</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>
每当我更改表单并自动提交时,都会显示一个新字段&#34; myfield&#34;被添加到URL结尾。如何让URL保持不变,并添加&#34; myfield&#34;查询到URL的末尾,而不是删除现有的URL查询字符串?
答案 0 :(得分:0)
将URL参数值存储在具有相同名称的隐藏字段中 例如:
网址:http://localhost/test.php?myfield1=x
<h1>Sort by</h1>
<form>
<input type='hidden' name='myfield1' value='<?php echo $_GET['myfield1']; ?>' />
<select name='myfield' onchange='this.form.submit()'>
<option value="Relevance">Relevance</option>
<option value="Date">Date Posted</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>