Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu November 25, 2022 . #Form . #HowTo

How to make a submit button redirect to another page in HTML

In this article, we will write a program that makes a submit button and whenever someone clicks on that button he will be redirected to a specific URL.

For this we will use the HTML <form> element and its action attribute.

<form action="https://www.3schools.in">
  <input type="submit" value="Click Me">
</form>
The action attribute specifies where to redirect a user when a form is submitted.

We must remember that for submitting a form we need to create an input element and its type will be submit.

As you can see in the above example we have used an input element whose type is submit. But if we use its type button while submitting the form then the form will not submit. For example :

<form action="https://www.example.com">
  <input type="button" value="Click Me">
</form>

I think you are thinking that what about the button element if we use the button element, the form will be submitted or not?

Yes, if you use the button element, the form will be submitted because by default its type is submit.

We can change the button type using the type attribute. The example is given below.

<form action="https://www.example.com">
  <button type="button">Click Me</button>
</form>

What is the purpose of submit button in HTML form? #

Basically HTML form is used to send form-data to a specific page. Suppose you have a form with an input element and a submit button. Now, you want to get the input value to the URL whenever someone clicks the submit button.

<form action="/search">
  <input type="text" name="url" placeholder="Type url">
  <button type="submit">Click Me</button>
</form>

But if your intention is only to send the user to a specific page then I think you should use the anchor element with its href attribute.

<a href="https://www.example.com">Click Me</a>
save
listen
AI Answer
Write Your Answer
loading
back
View All