views:

28

answers:

1

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?

A: 

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>
Lauri Lehtinen
The code above still doesn't work. It doesn't submit the form.
Tedd
Interesting, does *anything* happen? Refreshed the page?
Lauri Lehtinen
Nope. Nothing happens at all
Tedd
Not sure what could be wrong, maybe you could edit your post and paste the current code you're trying with .. I created a dummy page with the suggested change and it does submit.
Lauri Lehtinen
Shouldn't it go into the onclick event?
yodaj007
yoda, good question. Lauri - why isn't this using onclick?
Tedd
@Tedd, good question ;-) I guess I got distracted by you using the "javascript:..." notation, which works if put inside the href. Neither is "elegant", but either should work. By either I mean: href="javascript:document.getElementById('form_signup').submit();" or onclick="document.getElementById('form_signup').submit();"
Lauri Lehtinen