form action参数传递的几种方式

来源:互联网 发布:星摩网络 编辑:程序博客网 时间:2024/05/18 02:19
<!--
个人认为form的default method 是 ”post“,action后的#/?相同的效果,“.”代表current folder。
<form action="#"<?php if (isset($_GET['sample'])) echo "&this.sample.value"; ?>&this.data_format.value name=format_form>
<?php
if (isset($_GET['sample']))
echo "<input type=hidden   name='sample' value=" . $_GET['sample'] .">";
// note the space before "/>"
?>
-->
<form action="#" method=get name=format_form>
   <?php
if (isset($_GET['sample']))
echo "<input type=hidden   name='sample' value=" . $_GET['sample'] .">";
   ?>


显示格式选择

<SELECT size=1 name="data_format" id="data_format" onchange="submit()">

<OPTION value="0" <?php if ($format==0) echo "selected"; ?> >简略</OPTION>

<OPTION value="1" <?php if ($format==1) echo "selected"; ?> >详细</OPTION>

</select>



-----------------------------------------如何用js改变form的action属性值-------------------------

只要将form设定一个id如id=“form1”,然后在submit的时候调用js函数,在函数中引用form.action=

"1.asp?id="+value,即可改变form的action值,可以很好的控制跳转的参数,而不用把原本的html页面改成asp页面。

Eg:

<script lang="javascript">

function go()

{

var value=document.getElementById("T1").value;

form1.action="search.asp?cx="+value;

}

</script>



引用该函数的form:

<form id="form1" method=post onsubmit="go();">

我的方法:

if (document.form1.search_option1.value=="data" )

 {

document.form1.action = "data.php"; //js control the form by id,not name

document.form1.search_option2.options.length = 1;

document.form1.search_option2.options[0] = new Option("Dataset");

document.form1.search_option2.options[0].value = "Dataset_ID"; // 文本型value 必须用""

document.form1.search_option2.options[1] = new Option("位址");

document.form1.search_option2.options[1].value = "site";

document.form1.search_option2.selectedIndex = 0;

}


引用的form

<form action="b1_customer.php" method=post name="from1" id="from1">

        <SELECT onChange=checkSearch() size=1 name="search_option1" id="search_option1">xxxx</select>

<SELECT size=1 name="search_option2" id="search_option2">xxx</select>





记于2010.9.13     黯風夜隱

原创粉丝点击