Home > Groups > Web Development > Submit form without submit button or submit form using a link

Submit form without submit button or submit form using a link

Article
Published in

Let's go with example

1) Create a form within body tag

<form name="form1" id="form1" action="" method="post">
<input type="text" name="uname">
</form>

Generally when you click on submit button then form is submit but when submit button is not available then how you will submit. For that you should follow some simple steps

2) create a javascript function inside head or body section of your page

<script type="text/javascript" language="javascript">
function submitForm(){
document.form1.submit(); // We are submitting form1 when submitForm() function is call
return false;
}
</script>

3) Create a link <a href="#" onclick="submitForm();"> Submit</a> Outside the form. when user click on this then submitForm() function will call and form will be submit.

4) Finish

-----------------------------------------------------------------------------------------------------------------------------------------

Cut & Paste below code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function submitForm(){
document.form1.submit(); // We are submitting form1 when submitForm() function is call
return false;
}
</script>

</head>

<body>
<form name="form1" id="form1" action="" method="post">
<input type="text" name="uname">
</form>
<a href="#" onclick="submitForm();"> Submit</a>

</body>
</html>

Your rating: None Average: 3.4 (8 votes)

Bookmark and Share
Home Back To Top