表单提交后保持切换表

时间:2022-09-25 15:00:15

I have a php page that on load shows a table by default, and that table is:

我有一个php页面,加载时默认显示一个表,该表是:

echo "<table class='tftable' border='1' id='table_L'>";

There is another table:

还有另一张表:

echo "<table class='tftable' border='1' id='table_P' style='display:none'>";

which I toggle on the page by the following javascript function: function toggleTables(table_id)

我通过以下javascript函数在页面上切换:function toggleTables(table_id)

{
    if(table_id == "table_L") {
        document.getElementById('table_L').style.display = "table";
        document.getElementById('table_P').style.display = "none";
        }
    else if(table_id == "table_P") {
        document.getElementById('table_P').style.display = "table";
        document.getElementById('table_L').style.display = "none";
    }
}

So depending on which link user clicks, it displays the appropriate table. But then I have a form that based on selected values feeds the table data upon Submit. And the problem is, if user selects the table_P, which by default is hidden, then selects some dropdown values and submits the form, the page refreshes and table_L is loaded back again. How can I keep the same table selected even after the page reload? Is there some values I need to store to remember upon form submit?

因此,根据用户点击的链接,它会显示相应的表格。但是我有一个基于选定值的表单在提交时提供表数据。问题是,如果用户选择默认隐藏的table_P,然后选择一些下拉值并提交表单,页面刷新并再次加载table_L。如何在页面重新加载后保持选择相同的表格?在表单提交时是否需要存储一些值以便记住?

<form method="post" action="">
selections...

<INPUT TYPE="submit" name="submit" title="Run It!" value="SUBMIT" />
</form>

1 个解决方案

#1


0  

You could have a hidden field in the form that knows which table is currently visible. On submit, use that form data form the client to echo the proper table.

您可以在表单中有一个隐藏字段,该字段知道当前可见的表。在提交时,从客户端使用该表单数据来回显正确的表。

So your form would look like this:

所以你的表单看起来像这样:

<form method="post" action="">
  ...
  <input type="hidden" name="tableid" value="table_P">
  <button type="submit">Submit</button>
</form>

And serverside, the post body would contain the name of the table, and you would print the correct table.

而在服务器端,帖子正文将包含表的名称,您将打印正确的表。

#1


0  

You could have a hidden field in the form that knows which table is currently visible. On submit, use that form data form the client to echo the proper table.

您可以在表单中有一个隐藏字段,该字段知道当前可见的表。在提交时,从客户端使用该表单数据来回显正确的表。

So your form would look like this:

所以你的表单看起来像这样:

<form method="post" action="">
  ...
  <input type="hidden" name="tableid" value="table_P">
  <button type="submit">Submit</button>
</form>

And serverside, the post body would contain the name of the table, and you would print the correct table.

而在服务器端,帖子正文将包含表的名称,您将打印正确的表。