Is it safe to use anchor to submit form?

To use an anchor to submit a form would require the use of JavaScript to hook up the events. It’s not safe in that if a user has JavaScript disabled, you won’t be able to submit the form. For example:

<form id="form1" action="" method="post">
    <a href="#" onclick="document.getElementById('form1').submit();">Submit!</a>
</form>

If you’d like you can use a <button>:

<button type="submit">Submit!</button>

Or stick with what we all know:

<input type="submit" value="Submit!" />

You can style all three of them, but the latter two don’t require JavaScript. You probably just need to change some CSS somewhere if you’re having border issues.

Leave a Comment