setTimeout没有执行表单提交 [英] setTimeout not executing form submit

查看:87
本文介绍了setTimeout没有执行表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:延迟执行表单提交


代码(Javascript + JScript ASP):


<%

Response.Write("< OBJECT ID =''IntraLaunch''STYLE =''display:none''

WIDTH = 0 HEIGHT = 0 CLASSID =''CLSID:0AE533FE- B805-4FD6-8AE1-A619FBEE7A23''

CODEBASE =''IntraLaunch.CAB#version = 5,0,0,3''>")

回复.Write("< PARAM NAME =''ImageLoc''VALUE =''Null''>")

Response.Write("< PARAM NAME =''ImageSrc' 'VALUE =''Null''>")

Response.Write("< PARAM NAME ='''Run''

VALUE =''F :\\Axys3 \\Clarity \\report1.bat''>")

Response.Write("< PARAM NAME =''RunParms''VALUE =''''>")

Response.Write("< PARAM NAME =''显示''VALUE = MAX''>")

Response.Write("< / OBJECT>")< br $> b $ b%>


< script>


函数UpdateRec(theForm,rec){


tmp_checked = 0;


tmp_login = theForm.login.value;

tmp_year = theForm.tmp_year.value;

tmp_quarter = theForm.tmp_quarter.value;

tmp_comm = theForm.comm.value;


if(theForm [rec] .checked ){

tmp_checked = 1;

}


theForm.target =" MyFrame";

theForm.action =" qr_update.asp?axys =" + rec +"& tmp_quarter =" +

tmp_quarter +"& tmp_year =" + tmp_year +"& tmp_login =" + tmp_login +

"& tmp_checked =" + tmp_checked +"& tmp_comm =" + tmp_comm;

theForm.submit();

document.body.style.cursor =''wait'';

}


函数GenerateReport(theForm,rec,do_checkbox){


document.IntraLaunch.RunParms = rec;

IntraLaunch。 ExecuteIt(Null);


if(do_checkbox){

oldcomm = theForm.comm.value;

theForm .comm.value =" GSHOW";

theForm [rec] .checked = true;

UpdateRec(theForm,rec);

theForm.comm.value = oldcomm;

}


tmp_year = theForm.tmp_year.value;

tmp_quarter = theForm.tmp_quarter .value;

theForm.target =" MyOtherFrame";

theForm.action =" generate.asp?quarter =" + tmp_quarter +"& year =" +

tmp_year +"& axys =" + rec;


var timer = setTimeout(" document。" + theForm.name +" .submit()",2000);

clearTimeout(计时器);


// alert(" GenerateReport表单对象名:" + theForm.name);

//document.updateform .submit();

}


背景/说明:


这是一个任务状态跟踪网应用。这个

代码片段的目的是自动创建两个Axys报告作为文本

文件,将它们解析为PDF,并将它们整理成第三个PDF,所有这些都在

点击一个按钮。 GenerateReport是直接称为

的方法;对象声明和UpdateRec适用于您的

参考。这里的问题是通过IntraLaunch生成文本文件需要一些时间(一秒钟或两美元),我需要延迟

PDF操作(在generate.asp)直到完成。


代码本身是合理的 - 通过取消注释最后两行,

一切顺利,因为警报作为延迟。


我发现setTimeout根本没有执行表单提交:

我在< body onload =>中发出警报qr_update.asp和

generate.asp。 sans-setTimeout版本会弹出每个页面的警报,

但是如果我使用setTimeout,我只会收到qr_update的警报。不过,我感到很困惑,因为这似乎是通过setTimeout提交表格的正确语法


http://groups.google.com/groups?q=se...ft.com&rnum=10


请帮忙!


谢谢,

米歇尔

Goal: delay execution of form submit

Code (Javascript + JScript ASP):

<%
Response.Write("<OBJECT ID=''IntraLaunch'' STYLE=''display : none''
WIDTH=0 HEIGHT=0 CLASSID=''CLSID:0AE533FE-B805-4FD6-8AE1-A619FBEE7A23''
CODEBASE=''IntraLaunch.CAB#version=5,0,0,3''>")
Response.Write("<PARAM NAME=''ImageLoc'' VALUE=''Null''>")
Response.Write("<PARAM NAME=''ImageSrc'' VALUE=''Null''>")
Response.Write("<PARAM NAME=''Run''
VALUE=''F:\\Axys3\\Clarity\\report1.bat''>")
Response.Write("<PARAM NAME=''RunParms'' VALUE=''''>")
Response.Write("<PARAM NAME=''Display'' VALUE=MAX''>")
Response.Write("</OBJECT>")
%>

<script>

function UpdateRec(theForm, rec) {

tmp_checked = 0;

tmp_login = theForm.login.value;
tmp_year = theForm.tmp_year.value;
tmp_quarter = theForm.tmp_quarter.value;
tmp_comm = theForm.comm.value;

if(theForm[rec].checked) {
tmp_checked = 1;
}

theForm.target = "MyFrame";
theForm.action = "qr_update.asp?axys=" + rec + "&tmp_quarter=" +
tmp_quarter + "&tmp_year=" + tmp_year + "&tmp_login=" + tmp_login +
"&tmp_checked=" + tmp_checked + "&tmp_comm=" + tmp_comm;
theForm.submit();
document.body.style.cursor = ''wait'';
}

function GenerateReport(theForm, rec, do_checkbox) {

document.IntraLaunch.RunParms = rec;
IntraLaunch.ExecuteIt("Null");

if (do_checkbox) {
oldcomm = theForm.comm.value;
theForm.comm.value = "GSHOW";
theForm[rec].checked = true;
UpdateRec(theForm, rec);
theForm.comm.value = oldcomm;
}

tmp_year = theForm.tmp_year.value;
tmp_quarter = theForm.tmp_quarter.value;
theForm.target = "MyOtherFrame";
theForm.action = "generate.asp?quarter=" + tmp_quarter + "&year=" +
tmp_year + "&axys=" + rec;

var timer = setTimeout("document."+theForm.name+".submit()", 2000);
clearTimeout(timer);

//alert("GenerateReport form object name: " + theForm.name);
//document.updateform.submit();
}

background/explanation:

This is a task-status tracking web application. The purpose of this
code snippet is to automatically create two Axys reports as text
files, parse them into PDFs, and collate them into a third PDF, all on
the click of a button. GenerateReport is the method that''s called
directly; the object declaration and UpdateRec are there for your
reference. The issue here is that it takes some time (a second or
two) to generate the text files via IntraLaunch, and I need to delay
the PDF operations (performed in generate.asp) until this is done.

The code itself is sound -- by uncommenting the last two lines,
everything functions smoothly, since the alert acts as a delay.

I have found that setTimeout is not executing the form submit at all:
I placed alerts in <body onload=> of both qr_update.asp and
generate.asp. The sans-setTimeout version pops an alert for each page,
but if I use setTimeout, I only get an alert for qr_update. I am
puzzled, though, because this seems to be the correct syntax for form
submission via setTimeout:
http://groups.google.com/groups?q=se...ft.com&rnum=10

Please help!

Thanks,
Michelle

推荐答案

Mic说:
Mic said:
var timer = setTimeout(" document。" + theForm.name +" .submit()",2000);
clearTimeout(计时器);
var timer = setTimeout("document."+theForm.name+".submit()", 2000);
clearTimeout(timer);




setTimeout没有插入延迟。

它安排在指定的延迟后执行的某些任务。

执行立即进入下一行。


这两行说:

1.等待两秒钟,然后提交佛rm。

2.没关系。



setTimeout doesn''t insert a delay.
It schedules some task to be performed after a specified delay.
Execution proceeds immediately to the next line.

Those two lines say:
1. Wait two seconds, and then submit the form.
2. Nevermind.


是的,修好了。


1)我觉得迟钝了

2)你很棒 - 谢谢!!!!!


:-)
Yep, that fixed it.

1) I feel retarded
2) You''re awesome -- thanks!!!!!

:-)


Lee写道:
Lee wrote:
Mic说:
var timer = setTimeout(" document。" + theForm.name +" .submit()",2000);
clearTimeout(计时器);
var timer = setTimeout("document."+theForm.name+".submit()", 2000);
clearTimeout(timer);



setTimeout没有插入延迟。
它安排了一些在指定的延迟之后执行的任务。



setTimeout doesn''t insert a delay.
It schedules some task to be performed after a specified delay.




实际上,如果提供了一个字符串作为第一个参数,setTimeout()会调度

表达式在指定的延迟后进行评估。如果提供了一个

函数对象引用,则调用引用的函数,

使用setTimeout()的第三个和后面的参数作为
$ b的参数$ b函数[仅限JavaScript 1.2 + / Gecko-DOM; IE-DOM确实支持从v5.0开始的
函数引用,但没有支持日期的其他参数

(IE 6.0 SP-1) - setTimeout(alert,2000 ,42)在IE中产生一个空的消息框

,但不在NN4 + / Mozilla中。]


但是,使用的表达式不是最佳的document.FormName不是符合
标准的参考(即未在W3C-DOM Level 1+中指定)。

而是指定document.forms [" FormName"],因此更好的

声明是


var timer =

setTimeout(" document.forms [''" + theForm .name +"'']。submit()",2000);





var timer =

setTimeout(document.forms [theForm.name] .submit,2000);


然而,如果<检查(调用用户定义的方法)会更好br />
在访问它之前有document.forms [theForm.name] .submit()。对于

第一个变体,如在超时中使用的那样,如果窗口的内容在此期间发生了变化,那么纯粹的,未经检查的声明

可能会失败某些原因是
。对于第二个变体,查找路径的一部分可能是

非引用,已经导致分配时出现脚本错误。

因此应该使用


函数submitForm(sFormName)

{

var f,t;

if(document

&& document.forms

&&(f = document.forms [sFormName])

&&((t = typeof f.submit)==" function"

|| t ==" object")

{

f.submit( );

}

}


var timer = setTimeout(" submitForm(" + theForm.name +" )",2000);

PointedEars



Actually, if provided a string as first argument, setTimeout() schedules
that expression to be evaluated after a specified delay. If provided a
Function object reference instead, the function referred to is called,
using the third and following arguments of setTimeout() as arguments for
the function [JavaScript 1.2+/Gecko-DOM only; the IE-DOM does support
function references from v5.0 on, but not additional arguments to date
(IE 6.0 SP-1) -- setTimeout(alert, 2000, 42) yields an empty message box
in IE, but not in NN4+/Mozilla.]

However, the used expression is suboptimal as document.FormName is not a
standards compliant reference (i.e. not specified in W3C-DOM Level 1+).
Instead document.forms["FormName"] is specified there, thus the better
statement is either

var timer =
setTimeout("document.forms[''"+theForm.name+"''].submit()", 2000);

or

var timer =
setTimeout(document.forms[theForm.name].submit, 2000);

Yet it would be much better to check (calling a user-defined method) if
there is document.forms[theForm.name].submit() before accessing it. For
the first variant, as used in a timeout, the pure, unchecked statement
is likely to fail if the window''s content has changed in the meantime for
some reason. For the second variant, a part of the lookup path may be a
non-reference anyway, already causing a script error on assignment.
Therefore one should use

function submitForm(sFormName)
{
var f, t;
if (document
&& document.forms
&& (f = document.forms[sFormName])
&& ((t = typeof f.submit) == "function"
|| t == "object")
{
f.submit();
}
}

var timer = setTimeout("submitForm(" + theForm.name + ")", 2000);
PointedEars


这篇关于setTimeout没有执行表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆