JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" />
<button class="validate" onclick="window.location='www.google.com'">validate</button>
JavaScript
var x = $("button.validate").attr("onclick"); //get the onclick and store it in a variable.
$("button.validate").attr("onclick", ""); //remove the onclick attribute for that button
$("button.validate").click(function() {
//Now do validations for your button.
if ($("input[type='text']").val() == "10") {
eval(x); //If the form fields passed the validation
//then trigger the redirect using eval
}
});