How to submit a form by clicking a link in JavaScript ? Last Updated : 27 May, 2024 Comments Improve Suggest changes Like Article Like Report 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. ApproachHTML 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. HTML <!DOCTYPE html> <html> <body> <h2 style="color:green">GeeksforGeeks</h2> <b>Submit form details</b> <form id="form__submit" action="form.php" method="post"> <label>NAME: </label><br /> <input type="text" name="name" /><br /> <label>AGE: </label><br /> <input type="number" name="age" /><br /> <label>CITY: </label><br /> <input type="text" name="city" /><br /><br /> <a href="#" onclick="submitForm()">Submit Here</a> </form> <script> function submitForm() { let form = document.getElementById("form__submit"); form.submit(); } </script> </body> </html> Note: The given HTML code will redirect the form data to the site or file which is mentioned in the action attribute. 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. PHP <?php $name=$_POST['name']; $age=$_POST['age']; $city=$_POST['city']; echo "NAME-SUBMITTED : $name <br>"; echo "AGE-SUBMITTED : $age <br>"; echo "CITY-SUBMITTED: $city"; ?> Output: user form dataPHP is a server-side language. So it requires a server. Please refer PHP tutorial for a better understanding. Comment More infoAdvertise with us Next Article How to submit a form by clicking a link in JavaScript ? A anuragsingh1022 Follow Improve Article Tags : JavaScript Web Technologies HTML PHP-basics HTML-Questions JavaScript-Questions +2 More Similar Reads How to Disable Submit Button on Form Submit in JavaScript ? Forms are a crucial part of web development as they allow users to submit data to a server. However, sometimes we want to customize the behavior of HTML forms and prevent the default behavior from occurring. This allows you to create a more interactive and user-friendly web application. In this arti 3 min read How to Simulate a Click in JavaScript? Simulating a click in JavaScript means triggering a click event on an HTML element using code, rather than requiring manual user interaction. This technique is useful for automating actions like clicking buttons, links, or other interactive elements, enhancing web functionality, and triggering hidde 3 min read How to Create a Link in JavaScript ? In JavaScript, a link typically refers to creating HTML hyperlinks (<a> tags) dynamically using JavaScript. You can link using a document.createElement('a'), setting attributes like href and textContent, and then appending it to the document with appendChild().Here are some common approaches t 4 min read How to Open a Link Without Clicking on it using JavaScript? To open a link without clicking on it we can use the onmouseover method of JavaScript. The link will open when the mouse moves over the text. It returns a newly created window, or NULL if the call gets failed. Syntax:window.open( URL, name, Specs )Note: Allow Pop-up of Web Browser. Example 1: URL is 1 min read How to Call a JavaScript Function from an onsubmit Event ? The onsubmit event attribute in HTML is triggered when a form is submitted. It is also useful for validating form data or performing actions before any submission and ensures better control and validation of user inputs before data is sent. The below methods can be used to call a JavaScript function 2 min read Like