<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
This is the sample code from bootstrap, how can I add a link in this button while keep the data validation?
Link to another html file after clicked.
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
This is the sample code from bootstrap, how can I add a link in this button while keep the data validation?
Link to another html file after clicked.
To add a link to a submit button in HTML while maintaining data validation, you can use JavaScript or jQuery to achieve the desired functionality. Here are a few options you can consider:
Using JavaScript:
onclick
event handler to the button and use window.location.href
to redirect to the desired HTML file.<button class="w-100 btn btn-lg btn-primary" type="submit" onclick="window.location.href='path/to/your/file.html'">Sign in</button>
Using jQuery:
window.location.href
to redirect to the desired HTML file.<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.btn-primary').click(function() {
window.location.href = 'path/to/your/file.html';
});
});
</script>
<button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button>
Please note that these solutions will redirect the user to another HTML file upon clicking the button. However, it's important to mention that using a submit button for navigation purposes may not be semantically correct according to HTML standards. The purpose of a form is typically to collect and submit user data, whereas using a submit button for navigation goes against this convention.
If you want to maintain data validation while navigating to another page, you may need to handle the validation logic separately. You can use JavaScript or jQuery to validate the form fields before redirecting the user to another page.
Remember to replace 'path/to/your/file.html'
with the actual path of the HTML file you want to link to.
I hope this helps!