
不用这么麻烦,你把表单的名称取成一样的就行了。例如:
表单页面:
function setid()
{
str='<br>';
for(i=1;i<=5;i++)
str+='姓~~名'+i+':<input type="text" name="name2" class="tx1" /><br /> <hr color="#FF0000">' ;
windowupidinnerHTML=str+'<br>'; //这里用来输出
}
接收页面:
name=requestfrom("name2")'这样取出来是一个数组,然后用split分解
nameArr=split(name,",")'然后再循环数组就可以取值了
for each item in nameArr
responsewrite item
next
也可以直接循环取值,这样更精简
for each item in requestfrom("name2")
responsewrite item
next
serialize() 方法通过序列化表单值,创建 URL 编码文本字符串。
您可以选择一个或多个表单元素(比如 input 及/或 文本框),或者 form 元素本身。
序列化的值可在生成 AJAX 请求时使用。
ession是后台服务器端的变量,而js是前段脚本,
在js中是没有现成的方法获取session的值的,需要通过服务器语言来获取。
比如java就可以用来获取session的值,再赋值给js变量。
以jsp为例,通过:
var id = '<%=sessiongetAttribute("id")%>';
java代码用单引号引起来,java中字符串变量用双引号
示例
可以做一个jsp简单的页面显示session的值:
先将session值置为Imsession,然后显示。调用jsp代码来运行
<html>
<head>
<title>自定义浏览页面</title>
<script type="text/javascript">
function x(){
<%sessionsetAttribute("id","Imsession");%>
var id = '<%=sessiongetAttribute("id")%>';
alert("session是"+id);
} </script>
</head>
<body>
<input type ="button" onClick="javascript:x();" value="session">
</body>
</html>
documentgetElementById('b')value
或者
form1avalue
在页面间传递,<script>function goURL(theform){ var gourl = "456html";
gourl +="p="+theformusernamevalue+"|"+theformemailvalue; theformaction = gourl; return true;
}</script><form method=get onsubnit="return goURL(this);
"><input type=text name=username><input type=text name=email><input type=button value=提交
onclick="goURL(thisform)"></form> 在456html页面用脚本叫URL问号后面的值分割后,再用"|"分割就得到username和email<script>function init(){ var url= documentlocationhrefsplit("")
temp =urlsplit("|");
alert("UserName="+temp[0]+"\n"+"Email="+temp[1]); }</script><body onload=init()> </body>
PHP 可以通过POST、GET方法获取到表单提交的数据 获取到的POST、GET是数组形式的值,需要通过键值来详细获取相应的值 比如: indexphp 页面 下面是POST方法 也可以是下面是GET方法 POST相对于GET方法,更好一些,可以提交大量数据,以及更安全些。
方法一:利用form的onsubmit()函数
Html代码
<script type="text/javascript">
function validateForm(){
if(documentreplytitlevalue == ""){ //通过form名来获取form
alert("please input the title!");
documentreplytitlefocus();
return false;
}
if(documentforms[0]contvalue == ""){ //通过forms数组获取form
alert("please input the content!");
documentreplycontfocus();
return false;
}
return true;
}
<form name="reply" method="post" onsubmit="return validateForm( );">
<input type="text" name="title" size="80" /><br />
<textarea name="cont" cols="80" rows="12"></textarea><br />
<input type="submit" value="提交" >
</form>
注意:
1onsubmit属性内容一定要有return关键字,否则函数会直接执行,不会返回
2validateForm一定要返回一个boolean类型的返回值
3提交按钮要写成submit类型的
PHP 可以通过POST、GET方法获取到表单提交的数据
获取到的POST、GET是数组形式的值,需要通过键值来详细获取相应的值
比如: indexphp 页面
下面是POST方法
<form name="form1" method="post" action="indexphp">
<input type="text" name="contents" value="">
<input type="submit" value="提交">
</form>
<php
以上就是关于如何获取多个表单数据全部的内容,包括:如何获取多个表单数据、jquery中怎么样获取表单所有值、session怎样获取表单的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)