与ASP中的document.form.submit()相关的问题

时间:2010-02-20 08:19:37

标签: javascript

网页上有3个按钮。在单击每个按钮时,会打开一个相同的弹出窗口(比如window1)。现在这个弹出窗口(window1)上还有另一个按钮,它进一步打开另一个弹出窗口(比如window2)。在从'window2'中选择一些值时,该值将传递到'window1'。 'window1'上有一个'查找'链接,它调用javascript函数'clicked()':

<head>
<%
Dim command
command = Request.Form("hid");
Response.Write(“Value” & command);  -- The value is not printed (Reason found after 
                                                   analysis that may be because the form is not submitted 
                                                    successfully)
%>

function clicked()
{
document.form.hid.value='FIND';
alert("before");              -- This message box appears
**document.form.submit();**  -- after a lot of analysis the conclusion is that 
                                  this submit statement stops working (as on the status   
                                  bar 'Opening https:.....File1.asp?form=...' is not 
                                  displayed when 'after' message box appears
alert("after");               -- This message box appears 
}

<body.......>
<% if command = "FIND" then
Response.Write ("Inside Find"); -- This message is not printed.
  // some functonality

%>
<form ....>

<input type="hidden" name="hid" value="">

</form>
</body>

此完整代码在我的计算机上正常运行。但是,当在客户端运行时,此代码无法正常工作!尽管正在访问相同的服务器和相同的已部署应用程序。没有特定的序列/方案,但是例如。 当说按钮1点击 - > window1打开 - &gt; window2打开 - >值选择 - >返回到window1->点击查找 - &gt;单击Ok-&gt;在主页面上返回。 然后重复相同的场景说第3个按钮。 (直到现在'查找'链接工作正常)。 现在重复了第二个按钮的相同场景,这里获得了'之后'的消息,但是没有打印'内部查找'!!

1 个答案:

答案 0 :(得分:0)

document对象没有form属性。

只有在表单上有属性name="form"且代码页面上只有一个带有该名称的表单时,代码才有效。这是表单的错误名称,因为DOM中的其他对象实际上具有form属性(即表单中的字段)。

您应该为表单指定一个明确的名称,并使用document.forms集合来访问表单,而不是依赖于将表单添加到文档命名空间。