Is it safe to use anchor to submit form?

穿精又带淫゛_ 提交于 2019-11-28 06:47:19

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.

joshua bissot
<!-- add the anchor token at the end of your action statement -->

<form method='post' action='this_page.php?put_peram=token#anchor_name'>
<input type='submit' value='click here'>

<!-- put the anchor right above where you want the page to  index -->

<a name="anchor_name></a>

Try to avoid javascript for the action. Use always submit button. Some users may be disabled javascript for security purpose.

Although you want to use javascript for submitting the value, add the below line before writing the<html> tag.

<!-- saved from url=(0014)about:internet--> <html>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!