JSFiddle - React, Tailwind, and code Playground
by mazzzzz
HTML
<input type="text" id="tt1" onClick="runScript('tt1')" onkeypress="tt1_KeyPress(event,'tt1');return CheckNumber(event);"/>
JavaScript
function CheckNumber(evt)
{
var e = evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
function tt1_KeyPress(e,id) {
//Also check to only accept numbers
if (e.keyCode == 13) {
runScript(id);
}
}
function runScript (id)
{
if ($('#'+id).val() != "")
alert("Submit "+id);
}