im trying to create a form that takes 3 values, a name, a weight and height. i want to force the user to only enter numbers and not letters, so using the isNumeric this works but only for WEIGHT, not height.
this is the current code
<script type='text/javascript'>
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
<form name="input" action="calc.html" method="get">
Name: <input type="text" id="firstname" maxlength="20"><br>
Weight(KG): <input type="text" id="weight"><br>
Height(CM): <input type="text" id="height"><br>
<input type='button'
onclick="isNumeric(document.getElementById('weight'), 'Numbers Only Please')"
value='Check Field' />
</form>
i tried several things in order to incorporate the Height field as well such as ('weight')('height')
or ('weight'&&'height')
and even writing the whole line twice but with Height instead.
any help in solving this would be welcome.