VOOZH about

URL: https://www.geeksforgeeks.org/javascript/how-to-submit-a-form-by-clicking-a-link-in-javascript/

⇱ How to submit a form by clicking a link in JavaScript ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to submit a form by clicking a link in JavaScript ?

Last Updated : 23 Jul, 2025

Submitting a form by clicking a link in JavaScript involves binding a click event handler to the link element. When clicked, the handler triggers the form's submit action programmatically, allowing form submission without the need for a traditional submit button.

Approach

  • HTML Structure:
    • Basic HTML structure with a title, heading, and a form to submit details.
    • The form contains input fields for Name, Age, and City.
  • JavaScript Function:
    • submitForm() function triggered by clicking "Submit Here."
    • Retrieves the form by its ID and submits it.
  • Output:
    • Users enter details in the form.
    • Clicking "Submit Here" triggers form submission.

Example: In this example, we have followed the above approach.

Note: The given HTML code will redirect the form data to the site or file which is mentioned in the actionattribute.

PHP Code: Create a PHP file to get the user entered form data, rename this PHP file as "form.php". This code displays the user form data.

Output:

👁 Image
user form data

PHP is a server-side language. So it requires a server. Please refer PHP tutorial for a better understanding.

Comment