I’ve got a problem
i want to use both these javascripts, but i can’t make it work.
i have 1 button on my form, and when i press it, i have to check if the input box is empty and if the value is a number
can anyone help me
the first one is?to check if its is a decimal)
<SCRIPT LANGUAGE=”JavaScript”>
function checkDecimals(fieldName, fieldValue) {
decallowed = 0; // how many decimals are allowed?
if (isNaN(fieldValue) || fieldValue == “”) {
alert(“Oops! That does not appear to be a valid number. Please try again.”);
fieldName.select();
fieldName.focus();
}else {
if (fieldValue.indexOf(‘.’) == -1) fieldValue += “.”;
dectext = fieldValue.substring(fieldValue.indexOf(‘.’)+1, fieldValue.length);
if (dectext.length > decallowed){
alert (“Oops! Please enter a number with up to ” + decallowed + ” decimal places. Please try again.”);
fieldName.select();
fieldName.focus();
}
}
}
</script>
with this form:
<form action=”test.html”>
Please enter a number with up to 2 decimal places: <br>
<input type=text name=”aantalbest”>
<input type=button name=ok value=”Ok” onClick=”checkDecimals(this.form.aantalbest, this.form.aantalbest.value)”>
</form>
and this script(to check if ipnut is not empty)
<Script lanaguage=”javascript”>
function Valideren(aform)
{
if (aform.aantalbest.value == “”)
{
alert(“Geef een aantal door aub…”);
aform.aantalbest.focus();
return(false);
}
return(true);
}
</script>
with this form
<FORM action=”test2.html” method=”POST” onSubmit=”return Valideren(this)”>
<INPUT Name=”aantalbest” size=”50″>
<INPUT type=”SUBMIT” value=” Toevoegen “>
</FORM>