jquery问题...一种自动提交表单并进入下一步的方法?

时间:2010-02-02 21:49:02

标签: jquery forms submit

基本上,我有一个分为4种形式的过程(因此,4个网址),但我想完全绕过第三种形式。我无法真正了解代码本身,因为它来自第三方提供商而非开源。我希望做的是使用jquery在用户进入第三步时立即自动填写并提交表单,并快速/自动地执行,页面本身实际上是看不见的...就像这样那可行吗?

所以,这是一个简化的过程细分......

STEP ONE: http://sample.com/step1.aspx

<form name="step1">
<input type="text" name="stepone" value="" />
<input type="submit" name="steponesubmit" value="Submit" />
</form>

STEP TWO: http://sample.com/step2.aspx
<form name="step2">
<input type="text" name="steptwo" value="" />
<input type="submit" name="steptwosubmit" value="Submit" />
</form>


STEP THREE: http://sample.com/step3.aspx
(This is the one I'd like to fill out and submit automatically... 
 Basically, I want to mimic the user having pressed the "Agree" button)
<form name="step3">
<input type="submit" name="stepthreeagree" value="Agree" />
<input type="submit" name="stepthreedisagree" value="Disagree" />
</form>

STEP FOUR: http://sample.com/step4.aspx
<form name="step4">
<input type="text" name="stepfour" value="" />
<input type="submit" name="stepfoursubmit" value="Submit" />
</form>

3 个答案:

答案 0 :(得分:2)

您可以jQuery('input[name=stepthreeagree]').trigger('click').如果表单DOM可用。

或者您可以尝试使用适当的数据发布/到达该位置。即

jQuery.post('blahblah.html',{ stepthreeagree: 'Agree' })

通常情况下,这些多步骤形式以菊花链方式链接其数据(通过会话或隐藏输入),因此此解决方案可能不够充分。

只是评论:听起来有点像你在做一些粗略的事情。这里有一个很好的理论问题,但你为什么试图绕过某人的协议表?

Sarfraz:多个提交按钮有效。被点击的是提交其值的那个。不确定这是规范,还是仅仅是PHP的情况。

答案 1 :(得分:0)

首先,不要为单个表单使用两个提交按钮,例如:

不要使用:

<form name="step3">
  <input type="submit" name="stepthreeagree" value="Agree" />
  <input type="submit" name="stepthreedisagree" value="Disagree" />
</form>

使用:

<form name="step3" action="http://sample.com/step3.aspx">
  <input type="radio" name="agree" value="agree" checked="checked" />
  <input type="radio" name="agree" value="disagree" />
  <input type="submit" name="stepthreeagree" value="Submit" />
</form>

现在,由于已经选中了“同意”按钮,您可以像这样自动提交表单:

<script>
window.onload = function()
{
  document.step3.submit();
};
</script>

答案 2 :(得分:0)

您可以在所有网页上添加JavaScript吗?

如果是这样,在step2.aspx中你可以覆盖表单的提交,在AJAX中提交,然后定期提交第三个(例如将<form>添加到页面,使用jQuery提交)

这种方式step3.aspx甚至不会闪烁。

即使存在某种CSRF保护,您也可以从对AJAX提交的响应中获取CSRF保护字段。