Problem in validating number
Posted: Mon Aug 23, 2010 3:23 am
Hi, I had pass value's problem when validate number in PHP.
I do not know what error cause function cannot work
Hope someone can help me, thanks..
this is field.php
this is db.php
I do not know what error cause function cannot work
Hope someone can help me, thanks..
this is field.php
Code: Select all
<HEAD>
<TITLE>Number of Fields</TITLE>
</HEAD>
<script language="javascript">
function trim(str)
{
return str.replace(/^\s*|\s*$/g,"");
}
function number(tf)
{
for (x=0;x<tf.length;x++)
{
if (!isDigit(tf.charAt(x)))
{
return false;
}
}
return true;
}
function isDigit(dig)
{
return((dig<="9")&&(dig>="0")||dig==".");
}
function validateForm()
{
var validate=true;
var f=document.field;
if (trim(f.no_field.value)=="" && validate)
{
validate=false
alert("Please enter Number of Fields.")
f.no_field.focus()
}
if(!number(f.no_field.value))
{
validate=false
alert("Please enter NUMBERS in Number of Field.")
f.no_field.focus()
}
if (validate==true)
{
f.submit();
}
}
</script>
<BODY>
<form action="field.php" method="post" name="field" onsubmit="validateForm();">
<p></p>
<?php
echo " Please key in number fields you want";
?> <p></p>
<tr>
<td >Number of Fields:</td>
<td ><input type="text" name="no_field" class="ctr2"></td>
</tr>
<td align="right"><input type="button" value="confirm" onclick="validateForm();">
</form>
</BODY>
Code: Select all
<?php
include "../field.php";
$no_field= ($_POST['no_field']);
echo $no_field;
?>