我在我的旧站点中使用表单提交。由于 SEO 的目的,我将其更改为 onClick() 函数,这样它将转到一个干净的 URL,但是当我使用此函数时,其他表单值没有进入 php 文件
下面是我的旧代码
<form name="frmSearchTops" id="frmSearchTops" action="/womens/tops/" method="post">
<select name="cboCityNameRes" id="cboCityNameRes">
<option value=''>City</option>
{foreach from= $arritemCities item=foo}
{if $smarty.post.hdnCityName eq $foo}
<option value="{$foo}" selected="selected">{$foo}</option>
{else}
<option value="{$foo}" {if $foo eq 'City'} selected="selected"{/if}>
{$foo}
</option>
{/if}
{/foreach}
</select>
<select name="cboMaterial" id="cboMaterial">
<option value="">Material</option>
<option value="CT">Cotton</option>
<option value="SL">Silk</option>
</select>
<input name="btnSearch" type="button" value="Search" id="btnSearch"/>
</form>
新代码如下
JavaScript
<script type="text/javascript">
function searchitem()
{
$strCity = document.getElementById('cboCityNameRes').value;
window.location.href = "http://www.legacy.com/womens-tops-"+$strCity+".php";
}
</script>
HTML 代码
<select name="cboCityNameRes" id="cboCityNameRes" onchange="cityChanged()">
<option value=''>City</option>
{foreach from= $arritemCities item=foo}
{if $smarty.post.hdnCityName eq $foo}
<option value="{$foo}" selected="selected">{$foo} </option>
{else}
<option value="{$foo}" {if $foo eq 'City'} selected="selected"{/if}>
{$foo}
</option>
{/if}
{/foreach}
</select>
<select name="cboMaterial" id="cboMaterial">
<option value="">Material</option>
<option value="CT">Cotton</option>
<option value="SL">Silk</option>
</select>
<input name="btnSearch" type="button" value="Search" id="btnSearch" onclick="searchitem()"/>