收录日期:2019/08/18 17:16:40 时间:2010-06-16 01:05:36 标签:javascript,html,forms

I have the the following code and want to use a hyper link to submit my form.

<form name="form_signup" id="form_signup" method="post" action="/" enctype="multipart/form-data">
...
<input type="submit" value="Go to Step 2" name="completed" /> or <a onclick="javascript:this.form.submit();">Proceed without uploading</a></span>
</form>

However, my hyperlink submit doesn't work. It just keeps me on the same page.

Question: any idea why my link submit text doesn't work?

The this in your "javascript:this.form.submit();" refers to the <a> tag, which has no form property, resulting in a JavaScript error.

The smallest required change, but far from the most elegant, would be something like this:

<a href="javascript:document.getElementById('form_signup').submit();">...</a>