Home >Web Front-end >CSS Tutorial >How Can I Submit a Form Using a Link Instead of a Button?
Submitting a Form Using a Normal Link
When submitting a form, the typical approach is to use an button with the submit type. However, for aesthetic reasons, you may prefer to use a simple link.
Option 1: Styled Button
One option is to create a regular
<button type="submit" class="link-styled-button">Submit</button>
.link-styled-button { color: #000; background: none; border: 0; text-decoration: underline; cursor: pointer; }
Option 2: Form Submission with a Link
Alternatively, you can use a plain link and handle the form submission through JavaScript. Here's how:
<a href="#" onclick="this.closest('form').submit();return false;">Submit</a>
This method leverages the closest() method to find the nearest parent form element and triggers its submission when the link is clicked. The return false; statement prevents the link from following its default behavior (navigating to the specified URL).
The above is the detailed content of How Can I Submit a Form Using a Link Instead of a Button?. For more information, please follow other related articles on the PHP Chinese website!