Categories
HTML

How to make an HTML form with two submit buttons and two “target” attributes?

Sometimes,. we want to make an HTML form with two submit buttons and two "target" attributes.

In this article, we’ll look at how to make an HTML form with two submit buttons and two "target" attributes.

How to make an HTML form with two submit buttons and two "target" attributes?

To make an HTML form with two submit buttons and two "target" attributes, we add the formaction attribute to each button.

For instance, we write

<!DOCTYPE html>
<html>
  <body>
    <form>
      <input
        type="submit"
        formaction="firsttarget.php"
        value="Submit to first"
      />
      <input
        type="submit"
        formaction="secondtarget.php"
        value="Submit to second"
      />
    </form>
  </body>
</html>

to set the formaction attribute of each button to the URL to make the request to when we click on it.

Conclusion

To make an HTML form with two submit buttons and two "target" attributes, we add the formaction attribute to each button.

Categories
HTML

How to run HTML file on localhost?

Sometimes, we want to run HTML file on localhost.

In this article, we’ll look at how to run HTML file on localhost.

How to run HTML file on localhost?

To run HTML file on localhost, we can use the http-server Node module.

First, we install Node.js in our system.

Then In CMD, run the command npm install http-server -g.

Next, we navigate to the path of your file folder in CMD and run the http-server command

Finally, we go to our browser and type localhost:8080.

Now we should see the page we want to load.

Conclusion

To run HTML file on localhost, we can use the http-server Node module.

Categories
HTML

How to submit a form when the return key is pressed with HTML?

Sometimes, we want to submit a form when the return key is pressed with HTML.

In this article, we’ll look at how to submit a form when the return key is pressed with HTML.

How to submit a form when the return key is pressed with HTML?

To submit a form when the return key is pressed with HTML, we can add an input with type attribute set to submit.

For instance, we write

<form action="" method="get">
  Name: <input type="text" name="name" /><br />
  Pwd: <input type="password" name="password" /><br />
  <div class="yourCustomDiv" />
  <input type="submit" style="display: none" />
</form>

to add an input with type set to submit in our form.

Then when we press enter, a submission is made by the form.

Conclusion

To submit a form when the return key is pressed with HTML, we can add an input with type attribute set to submit.

Categories
HTML

How to force download of image from src=”data:image/jpeg;base64…” with HTML?

Sometimes, we want to force download of image from src="data:image/jpeg;base64…" with HTML.

In this article, we’ll look at how to force download of image from src="data:image/jpeg;base64…" with HTML.

How to force download of image from src="data:image/jpeg;base64…" with HTML?

To force download of image from src="data:image/jpeg;base64…" with HTML, we set the download attribute on the anchor element.

For instance, we write

<a download="YourFileName.jpeg" href="data:image/jpeg;base64,iVBO...CYII=">
  <img src="data:image/jpeg;base64,iVBO...CYII=" />
</a>

to set the download attribute to the name of the downloaded file.

We set href to the base64 URL of the image to download it as an image when we click on it.

Conclusion

To force download of image from src="data:image/jpeg;base64…" with HTML, we set the download attribute on the anchor element.

Categories
HTML

How to cache an image in HTML?

Sometimes, we want to cache an image in HTML.

In this article, we’ll look at how to cache an image in HTML.

How to cache an image in HTML?

To cache an image in HTML, we can add a link element.

For instance, we write

<link rel="preload" href="bg-image-wide.png" as="image" />

to add a link element that has the href attribute set to the URL of the image to cache.

And we set the rel attribute to preload to preload the image.

Conclusion

To cache an image in HTML, we can add a link element.