How to Post Data With an HTML Anchor
HTML forms are submitted using either the "get" or "post" method, depending on the purpose of the form and the server script being used, if any. A form is normally submitted when the user presses the button generated by an "input" tag with the "type" attribute set to "submit." An HTML form can also be submitted via JavaScript. Invoke a JavaScript function in the "onClick" attribute of an anchor ("a") tag to let the user submit a form with the "post" method by clicking a hyperlink instead of a button.
Instructions
-
-
1
Insert the following JavaScript code between the "head" tags of your HTML document:
<script type="text/javascript">
function submitForm(id){
document.getElementById(id).submit();
}
</script>
-
2
Add the following code to the body of your HTML document, specifying the location of your server-side script, if applicable, in the "action" attribute:
<form id="form1" method="post" action="/cgi-bin/formhandler.cgi"><input type="text" name="textinput" /></form>
<a href="#" onClick="submitForm('form1');">Submit form</a>
-
-
3
Publish your page to your Web server and navigate to it in a Web browser. Fill out the input field and click the link to post the data.
-
1