Categories
HTML

How to submit an HTML form without redirection?

Sometimes, we want to submit an HTML form without redirection.

In this article, we’ll look at how to submit an HTML form without redirection.

How to submit an HTML form without redirection?

To submit an HTML form without redirection, we can redirect to an invisible iframe.

For instance, we write

<iframe name="dummyframe" id="dummyframe" style="display: none"></iframe>

<form action="submitscript.php" target="dummyframe">...</form>

to add a hidden iframe with

<iframe name="dummyframe" id="dummyframe" style="display: none"></iframe>

And then we set the form’s target attribute to the ID of the hidden iframe to redirect to it after form submission is done.

Conclusion

To submit an HTML form without redirection, we can redirect to an invisible iframe.

Categories
HTML

How to handle floats and decimal separators with HTML input type number?

Sometimes, we want to handle floats and decimal separators with HTML input type number.

In this article, we’ll look at how to handle floats and decimal separators with HTML input type number.

How to handle floats and decimal separators with HTML input type number?

To handle floats and decimal separators with HTML input type number, we can set the pattern and step attributes.

For instance, we write

<input type="number" name="price" pattern="[0-9]+([\.,][0-9]+)?" step="0.01" />

to add a number input.

We set its pattern attribute to a pattern that we use to validate that the number entered is a decimal number.

And we set the step attribute to 0.01 to keep the number entered to 2 decimal places.

Conclusion

To handle floats and decimal separators with HTML input type number, we can set the pattern and step attributes.

Categories
HTML

How to download a PDF file instead of opening them in browser when clicked?

Sometimes, we want to download a PDF file instead of opening them in browser when clicked.

In this article, we’ll look at how to download a PDF file instead of opening them in browser when clicked.

How to download a PDF file instead of opening them in browser when clicked?

To download a PDF file instead of opening them in browser when clicked, we can add the download attribute to the link.

For instance, we write

<a href="http://link/to/file" download="FileName">Download it!</a>

to set the download attribute of the anchor element to the file name of file when we download it.

Then when we click on the link, the file will be downloaded.

Conclusion

To download a PDF file instead of opening them in browser when clicked, we can add the download attribute to the link.

Categories
HTML

How to select multiple files with file input in HTML?

Sometimes, we want to select multiple files with file input in HTML.

In this article, we’ll look at how to select multiple files with file input in HTML.

How to select multiple files with file input in HTML?

To select multiple files with file input in HTML, we add the multiple attribute.

For instance, we write

<input type="file" name="fileField" multiple="multiple">

to add the multiple attribute to the file input and set it to multiple to enable multi-file upload.

Conclusion

To select multiple files with file input in HTML, we add the multiple attribute.

Categories
HTML

How to prevent refresh of page when button inside form clicked?

Sometimes, we want to prevent refresh of page when button inside form clicked.

In this article, we’ll look at how to prevent refresh of page when button inside form clicked.

How to prevent refresh of page when button inside form clicked?

To prevent refresh of page when button inside form clicked, we set the type attribute of the button to button.

For instance, we write

<button type="button">Click</button>

to add a button in the form with the type attribute set to button to prevent refresh of the page when we click on the button.

Conclusion

To prevent refresh of page when button inside form clicked, we set the type attribute of the button to button.