I've read somewhere, that using anchor tag to submit a form isn't very safe, so that's my question: Is it safe, to use anchor tag instead of <button>
or <input type="submit" />
to submit a form? And if it isn't, why? The problem is, that I have a CSS class for a button, that shows what I want on <a class="button">
, but if I add it to an actual button it adds a weird border that I don't want.
Thanks
You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.
Most HTML forms have a submit button at the bottom of the form. Once all of the fields in the form have been filled in, the user clicks on the submit button to record the form data. The standard behaviour is to gather all of the data that were entered into the form and send it to another program to be processed.
The anchor tag is essentially a tag that you can attach to a word or a phrase (exactly like you would a normal internal or external link), except it brings readers down to a different section of the page as opposed to another webpage. You're essentially creating a unique URL within the same page when you use this tag.
Link Submit Button Using Anchor Tags In HTML In HTML, linking submit buttons using the Anchor Tag is a simple and dependable approach. Write/Declare a Submit button between the Anchor tag's Starting and Closing tags. Give a Path where you wish to link your Submit Button by using the href property of the Anchor element.
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.
<!-- 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With