How to valid the text after the data is insert into the text. If input with alphabet, it will pop out with alert at the same time
. The data should be only insert with numbering form. HTML should be continue use by oninput or oncheck or other on function?
function chicken()
{
var foodchicken=0;
var theForm = document.forms["energyform"];
var chicken = theForm.elements["chicken"];
var ttlchicken = document.getElementById("textbox1").value;
if(chicken.checked===true)
{
foodchicken = ttlchicken*10;
}
return foodchicken;
}
function calculateTotal()
{
var HMontotalco = chicken()
var hmco = document.getElementById('totalHMonthCst').innerHTML = +HMontotalco.toFixed(2)
}
<body onload='hideTotal()'>
<div id="all">
<form id="energyform" onsubmit="return false;">
<div>
<div class="cont_order">
<fieldset>
<br/>
<label for='chicken' class="chick">Chicken </label></hr>
<input type="checkbox" id="chicken" name='chicken' onchange="calculateTotal()">
<input type="text" oninput="calculateTotal();" id="textbox1" name="textbox1" placeholder="Enter total chicken" />
<br/>
<div id="totalHMonthCst">0</div>
</div>
</form>
</div>
</body>
</html>
if (isNaN(ttlchicken)) { alert('hey!'); return 0; }
Or, use atype="number"
input. - Johnny Mopp