javascript 传值给asp接收不了

zglhr 2009-08-14 02:58:13
1: <INPUT type=checkbox value="<%=rs("keyno")%>" name=PartID>
2: <INPUT onclick="javascript:selectall('form','PartID');" type=checkbox value=checkbox name=select>全选
<INPUT onClick="return sure('form','PartID','Del',this.value)" type=button value=删除>
<INPUT onClick="return sure('form','PartID','Update',this.value)" type=button value=更新>

3: function sure(FormName,FieldName,sort,str)
{
var k=document[FormName];
if(sort=="Cancel")
{
if (!window.confirm("确定要"+str+"吗?"))
{
return false;
}
k.Cancels.value = FieldName;
k.Actions.value = sort;
k.submit();
}
}

4: 想把这个k.Actions.value = sort;值传给asp页面,要如何接收
action=Request.Form("PartID")
response.Write(action)
...全文
88 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jspfaner 2009-08-14
还有加<form>
</form>
回复
mailbao 2009-08-14
刚调试了你的JS代码,错得一踏糊涂,表单传值的名称也前后矛盾,再者又长繁琐,跳来跳去有必要么?

用下面的方法来实现吧


<script language=javascript>
function CheckAll(form) {
var x = form.elements;
for (var i = 0; i < x.length; i++) {
var e = x[i];
if (e.name != 'chkall')
e.checked = form.chkall.checked;
}
}
</script>


<%
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [SubjectItem] where Menu_ZH order by ID desc",conn,1,1
if rs.eof And rs.bof then
Response.Write "<p align='center'> No data!</p>"
Response.End
end if
%>


<form name="form" id="form" method="post" action="">
<TABLE cellSpacing=0 cellPadding=0 width="98%" align=center border=0>
<%
i=1
do while not rs.EOF and i <=20
if (i mod 2)=1 then
Response.Write(" <tr bgcolor=fefefe>")
else
Response.Write(" <tr bgcolor=efefef>")
end if
%>
<TD align="middle"><%=rs("Menu_ZH")%></TD>
<TD align=middle><input name="SelectID" type="checkbox" id="SelectID" value="<%=rs("PartID")%>"></TD>
</TR>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
<TR valign="middle">
<TD align="middle"> </TD>
<TD align=middle>
全选<input type="checkbox" name=chkall onClick="CheckAll(this.form)"> <input type="submit" name="action" class="button"value="删除" onClick="{if(confirm('确定要删除吗?')){this.document.list.submit();return true;}return false;}">
  
<input type="submit" name="action" class="button"value="更新" onclick="{if(confirm('确定要更新吗?')){this.document.list.submit();return true;}return false;}" /></TD>
</TR>
</TABLE>
</form>

<%
getID=replace(request("SelectID"),"'","")
if request("action")="删除" then
'response.write request("action")
'response.end
call delCase()
end If
if request("action")="更新" then
'response.write request("action")
'response.end
call updateCase()
end If

sub delCase()
if getID="" or isnull(getID) then
response.write "<script>alert('操作失败!');</script>"
response.redirect "test.asp"
response.end

else
conn.Execute("delete * from [table] where ID in ("&getID&")")
response.write "<script>alert('删除成功!');</script>"
response.redirect "test.asp"
response.end
end if
end Sub

sub updateCase()
if getID="" or isnull(getID) then
response.write "<script>alert('操作失败!');</script>"
response.redirect "test.asp"
response.end

else
conn.Execute("update [table] set fieldname='test' where ID in ("&getID&")")
response.write "<script>alert('更新成功!');</script>"
response.redirect "test.asp"
response.end
end if
end Sub
%>
回复
zglhr 2009-08-14
还是不行,我把三部分代码都贴出来,看看有没有知道错在哪里的.
js部分

function selectall(FormName,FieldName,Type){
if (typeof(Type)=="undefined"){
for(var i=0;i<document[FormName].elements.length;i++){
var e=document[FormName].elements[i];
if((e.name).indexOf(FieldName)!=-1) e.checked = document[FormName].select.checked;
}
}else if (Type==1){
for(var i=0;i<document[FormName].elements.length;i++){
var e=document[FormName].elements[i];
if((e.name).indexOf(FieldName)!=-1) e.checked = true;
}
}else if (Type==0){
for(var i=0;i<document[FormName].elements.length;i++){
var e=document[FormName].elements[i];
if((e.name).indexOf(FieldName)!=-1) e.checked = !(e.checked);
}
}
}

function sure(FormName,FieldName,sort,str)
{
var k=document[FormName];
if(sort=="Cancel")
{
if (!window.confirm("确定要"+str+"吗?"))
{
return false;
}
k.Cancels.value = FieldName;
k.Actions.value = sort;
k.submit();
}
else
{

var z=0;
for (var i=0;i<k.elements.length;i++)
{
var s=k.elements[i];
if (s.checked && s.name==FieldName)z++;
}
if (z==0)
{
alert("请先选择要"+str+"的记录!")
return false;
}else{
if (!window.confirm("确定要"+str+"吗?"))
{
return false;
}
k.Actions.value = sort;
k.submit();
}
}
}

页面部分

<form name="form" id="form" method="post" action="">
<TABLE cellSpacing=0 cellPadding=0 width="98%" align=center border=0>
<%
i=1
do while not rs.EOF and i<=20
if (i mod 2)=1 then
Response.Write("<tr bgcolor=fefefe>")
else
Response.Write("<tr bgcolor=efefef>")
end if
%> <TR valign="middle">
<TD align="middle" style="WIDTH: 20px"><INPUT type=checkbox value="<%=rs("keyno")%>" name=PartID> </TD>
<TD align=middle><INPUT onClick="javascript:selectall('form','PartID');" type=checkbox value=checkbox name=select>全选
<INPUT onClick="return sure('form','PartID','Del',this.value)" type=button value=删除 name="ActionDo">
<INPUT onClick="return sure('form','PartID','Update',this.value)" type=button value=更新 name="ActionDo">
<BR></TD>
</TR>
</TABLE>
</form>

接收数据部分

if Request.ServerVariables("REQUEST_METHOD")="POST" then

ActionDo=request.form("ActionDo")
response.Write(ActionDo)

end if
回复
mailbao 2009-08-14

<form name="form1" id="form1" method="post" action="">
<INPUT type=checkbox value=" <%=rs("keyno")%>" name=PartID>
<INPUT onclick="javascript:selectall('form','PartID');" type=checkbox value=checkbox name=select>全选
<INPUT onClick="return sure('form','PartID','Del',this.value)" type=button value=删除 name=ActionDo>
<INPUT onClick="return sure('form','PartID','Update',this.value)" type=button value=更新 name=ActionDo>
</form>

function sure(FormID,FieldName,sort,str){
var k=document.getElementById(FormID);
if(sort=="Cancel")
{
if (!window.confirm("确定要"+str+"吗?"))
{ return false; }
k.Cancels.value = FieldName;
k.Actions.value = sort;
k.submit();
}
}


<%
'刪除
  if request.form("ActionDo")="DEL" then
  num=request.form("PartID").Count
  for i=1 to num
  conn.execute("delete from table where PartID="&request.form("PartID")(i))
  next
  end if

'更新
if request.form("ActionDo")="UPDATE" then
  num=request.form("PartID").Count
  for i=1 to num
  conn.execute("update table set name='a' where PartID="&request.form("PartID")(i))
  next
  end if
%>

回复
zglhr 2009-08-14
发送和接收值在同一个页面,现在我不知道怎么接收.
<form name="form1" id="form1" method="post" action="a.asp">
表單內容
</form>

要能获取
<INPUT onClick="return sure('form','PartID','Del',this.value)" type=button value=删除>
<INPUT onClick="return sure('form','PartID','Update',this.value)" type=button value=更新>
这个里面的'Del'和'Update',才能分别做更新和删除操作.


接收的内容要怎么写??
回复
王者coco 2009-08-14
up
回复
linmingnet 2009-08-14
你用客戶端腳本,給服務器傳值肯定接愛不到的,。。除非你讓它轉向到網頁刷新一下,然後在接受
location.href=''這樣
回复
shenzhenNBA 2009-08-14
适当修改

<form name="form1" id="form1" method="post" action="a.asp">
表單內容
</form>

function sure(FormID,FieldName,sort,str){
var k=document.getElementById(FormID);
if(sort=="Cancel")
{
if (!window.confirm("确定要"+str+"吗?"))
{ return false; }
k.Cancels.value = FieldName;
k.Actions.value = sort;
k.submit();
}
}
回复
mailbao 2009-08-14
[Quote=引用 2 楼 zglhr 的回复:]
接收不到值啊,用了onClick还要不要判断有没有用post
[/Quote]


沒值,可能你的代碼沒有用到
<form name="form1" method="post" action="a.asp">
表單內容
</form>
回复
mailbao 2009-08-14
selectstr=request("PartID")
if selectstr<>"" then
selectarray=split(selectstr,",")
for i=0 to ubound(selectarray)
response.write selectarray(i)&","
response.end
next
end if


如果你要更新sql
那sql語句類似如下
update table set name='a' where PartID in('"& selectarray & "')
回复
zglhr 2009-08-14
接收不到值啊,用了onClick还要不要判断有没有用post
回复
xinyung 2009-08-14
action=Request.Form("Actions")
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告