使用方法GET Automatic提交表单

时间:2014-03-26 09:52:51

标签: javascript php forms submit

我想提交一个方法GET的表单,如下所示:

search.php?q=Clothing&p=1&per=10

当我尝试这段代码时,我得到:

search.php?per=10

这是我的代码:

<?php

echo '<div id="filter">';
echo '<form action="search.php?q='.$q.'&p='.$page.'" name="per" method="get">';
echo '<div class="pages_filter"><div class="total_results">About <span>'.$result_count.'</span> results</div>';
echo '<div class="option_results">'.$total_pages.' Pages 
      <select id="resultsPerPage" name="per" onchange="autoSubmit()">';
for ($z = 0 ; $z <= 40 ; $z++){
$z=$z+10;
echo '<option type="submit" ';if ($z==$p){echo ' selected="selected "';} echo ' value="'.$z.'">'.$z.'</option>';
$z=$z-1;
}
echo '</select> Per page.
</form>
</div></div>';
echo '</div>'; /// #filter

?>

Javascript代码:

<script language="JavaScript">
function autoSubmit()
{
     var formObject = document.forms['per'];
     formObject.submit();
}
</script>

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个

echo '<form action="search.php" name="per" method="get">';
echo '<input type="hidden" name="q" value="'.$q.'" />';
echo '<input type="hidden" name="p" value="'.$page.'" />';