如何将select选项中的值传递给其他形式的其他选择选项
I want to move data from one form to another form with similar inputs in diferent pages, as I do to make the select option to acquire the same value when I submit form1 and form2 sees.
<form action="form2.html" method="post">
<select name="selection" >
<option value="" selected="selected">select one</option>
<option value="1" >one</option>
<option value="2" >two</option>
<option value="3" >three</option>
</select>
i need to get this value in the second form "form2.html"
how i can do this?
thanks !!
我想将数据从一个表单移动到另一个表单,在不同的页面中使用类似的输入,就像我做的那样 当我提交form1和form2看到时,选择选项以获取相同的值。 p>
&lt; form action =“form2.html”method =“post”&gt;
&lt; select name =“selection”&gt;
&lt; option value =“”selected =“selected”&gt;选择一个&lt; / option&gt;
&lt; option value =“1”&gt; one&lt; / option&gt;
&lt; option value =“2”&gt; two&lt; / option&gt;
&lt; option value =“3”&gt; three&lt; / option&gt;
&lt; / select&gt;
code> pre>
我需要以第二种形式“form2.html”获取此值 p>
我该怎么做? p>
谢谢!!
div>
The action page is necessarily a server page. You have to set the second page say, as form2.php. The data you submit here will go to the form2.php as a post value. It will be something like this :
<form action="form_submit.php" method="post">
<select name="selection2" >
<option value="1" <?php if($_POST['selection'] =="1"){echo "selected='selected'";}?> >one</option>
<option value="2" <?php if($_POST['selection'] =="2"){echo "selected='selected'";}?>>two</option>
<option value="3" <?php if($_POST['selection'] =="3"){echo "selected='selected'";}?>>three</option>
</select>
</form>
Thus you can get the value in the previous value selected in your new form. Otherwise you may use session to store the value temporarily.
There is not a trivial answer, you could set a $_SESSION variable, save in cookie, save in database and then SELECT that data on the next page using the appropriate method.