Click to See Complete Forum and Search --> : form validation JS & PHP


paularun
03-02-2003, 07:44 PM
I'm a newbie (obviously) and can't figure out why the JS code is not be execited. Any ideas??

Thanks!

<html>

<head>
<script language="JavaScript">
<!-- // ignore if non-JS browser
function validator(theform)
{
var error = "";
var digits = "0123456789";

if (theform.dd.options[0].selected == true)
{
error += "Please select product from the dropdown list.\n";
}
if (theform.quantity.value == "")
{
error += "Please fill in numeric quantity.\n";
}

for (var i = 0; i < theform.quantity.value.length; i++)
{
temp = theform.quantity.value.substring(i, i+1)

if (digits.indexOf(temp) == -1 &&
theform.number.value != "")
{
error += "The quantity must be numeric.\n";
break;
}
}

if (error != "")
{
alert(error);
return (false);
}
}
// -->
</script>


<title>Order Form</title>
</head>

<body>
<?
echo '<form target="_open" action="https://www.paypal.com/cgi-bin/webscr" method="POST" onSubmit="return validator(this);"> ';
echo '<input type="text" name="quantity" size="3" value="" ><font size="1">&nbsp; Qty &nbsp;<br>';
echo '<br>';
echo "<select size=\"1\" name=\"dd\">";
echo "<option value=1>".stripslashes($row["price1"])."</option>";
echo "<option value=2>".stripslashes($row["price2"])."</option></select>&nbsp;&nbsp;&nbsp;";
echo "<font size=\"1\"><button name=\"B3\">Add to Cart</font></button>";

echo "<input type=\"hidden\" name=\"item_name\" value=".stripslashes($row["prod_name"]).">";
if($selection == '1'){
echo "<input type=\"hidden\" name=\"amount\" value=".stripslashes($row["price1"]).">";
}
elseif($selection == '2')
{
echo "<input type=\"hidden\" name=\"amount\" value=".stripslashes($row["price2"]).">";
}
echo '</form>';

?>
</body>

</html>

pyro
03-02-2003, 08:20 PM
Well, your first problem would be that you have no submit button submitting the form. Thus, the validator will not be running at all. There may be more, but that is one thing I noticed. If that doesn't fix it, let us know...

paularun
03-02-2003, 08:32 PM
Oh boy do I ever feel stupid. Sometimes it just takes another set of eyes...

THANK YOU Pyro!