Hi friends,
My form have a text field named "price" which should have only number and if it contains decimal number then it should not have more than two numbers after decimal. I tried this but it is not working . If the data entered is valid (as described above) then it should post to the target.php .....
I hope u will point out my mistake OR u may advice some wise alternative for this ..
thanks.....
The code goes as follows.....
[HTML]<html>
<head>
<script type="text/javascript">
function checkForm()
{
// var price = document.form1. price;
document.form1. submit();
var value=document. getElementById( 'price').value;
var indx=value.inde xOf('.');
var digit=value.sub string(indx+1);
if(digit.length >2)
{
alert('only two decimal digit allowed');
document.form1. price.focus();
price.select();
document.form1. price.focus();
return false;
}
else
{
document.form1. submit();
}
}
</script>
</head>
<body>
<form name="form1" id="price" method="post" action="print selected area.html" >
<input name="price" type="text" id="price" size="25" maxlength="16" />
<input type="button" name="submit" value="ADD" onsubmit="chkFo rm()"/>
</form>
</body>
</html>
[/HTML]
My form have a text field named "price" which should have only number and if it contains decimal number then it should not have more than two numbers after decimal. I tried this but it is not working . If the data entered is valid (as described above) then it should post to the target.php .....
I hope u will point out my mistake OR u may advice some wise alternative for this ..
thanks.....
The code goes as follows.....
[HTML]<html>
<head>
<script type="text/javascript">
function checkForm()
{
// var price = document.form1. price;
document.form1. submit();
var value=document. getElementById( 'price').value;
var indx=value.inde xOf('.');
var digit=value.sub string(indx+1);
if(digit.length >2)
{
alert('only two decimal digit allowed');
document.form1. price.focus();
price.select();
document.form1. price.focus();
return false;
}
else
{
document.form1. submit();
}
}
</script>
</head>
<body>
<form name="form1" id="price" method="post" action="print selected area.html" >
<input name="price" type="text" id="price" size="25" maxlength="16" />
<input type="button" name="submit" value="ADD" onsubmit="chkFo rm()"/>
</form>
</body>
</html>
[/HTML]
Comment