by InfraSavvy
How to use two submit button in one html form
In real time applications may chance come to use two submit button in one html form.For example in user registration application,having one html form named userpolicy.html,it getting user information and displaying user policy also it contains two submit button like Agree and Disagree.When user click Agree button his/her information will be stored in database.When user click Disagree it will go to home or any other file.So we have to find which submit button is clicked by user.Here is the solution to find user clicked submit button.
<!-- userpolicy.html -->
<html>
<body>
<form action="process.php" method="POST">
Name <input type="text" name="username">
Password <input type="password" name="password">
<!-- User policy goes here -->
<!-- two submit button -->
<input type="submit" name="agree" value="Agree">
<input type="submit" name="disagree" value="Disagree">
</form>
</body>
</html>
/* Process.php */
<?php
if($_POST['agree'] == 'Agree') {
$username = $_POST['username'];
$password = $_POST['password'];
/* Database connection goes here */
}
else {
header("Location:http://user/home.html");
}
?>
By using javascript also we can achieve this.
<html>
<head>
<script language="javascript">
function funAgree(){
document.form1.action="addDB.php";
}
function funDisagree(){
document.form1.action="home.html";
}
</script>
</head>
<body>
<form name="form1" action="" method="POST">
Name <input type="text" name="username"> <br>
Password <input type="password" name="password"> <br>
<!-- User policy goes here -->
<!-- two submit button -->
<input type="submit" name="agree" value="Agree" onclick="funAgree()">
<input type="submit" name="disagree" value="Disagree" onclick="funDisagree()">
</form>
</body>
</html>
27 thoughts on “How to use two submit button in one html form”
hello my name is angella
Thank you for code, it works well, i am talking about 2 submit’s with javascript. You save my time to mess around. Thank you again.
Zygis
great ! very helpful
This website is useful for individuals who are searching prayers and novenas and all.
nice code! it helps!
Nice Work
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
small but effective post
thanks…it helped me
Want it? ,
Thanks a lot! Nice quick solution that really helped me π
great explanation.. thanks
im looking this code for a couple of weeks..i cant imagine the solution is using function. thanks a lot bro. i thought its using secondary form for posting value..its really helped me a lot π
Thanks man, your a big help
just for informing you, your code is not detectable by IE6 !
and it just works for ie7+
i’m looking for the right way for IE6, i’ll post a comment as soon as i found a way
how to use link so it work as button in above code
Nice explanation. Thank you. it’s helped me a lot.
thx it helps me a lot..keep up value of sharing to others..may god bless u alwayz and protect you from danger
thnx it worked u savd my time:)
thaaanks!!
great solution!
Really Helpful
thanks a lot man……….. what’s nice code.
thanks again and again.
good work nice thanks for the post…. great
very helpful….
Thanks a lot bro…
thaaaaaaaaaaank you very much your great explanation
Tnxs a lot…. YOU save My Day… ^_^