Hi, at the moment i'm just experimenting with form validation with javascript and php...for some reason when i try the javascript without the php embedded it works...when i add the php code the form submits but not validation takes place, so if i submit an empty form it allows it, can anyone tell me what the problem is with my code below, thanks in advance, amar
<html>
<body>
<head>
<script language="JavaScript">
<!--
function validate_form ( )
{
valid = true;
if ( document.dvd_form.dvd_name.value == "" )
{
alert ( "Please fill in the 'dvd_name' box." );
valid = false;
}
return valid;
}
//-->
</script>
</HEAD>
<BODY>
<?php
if (isset($POST['submit'])) {
$db = mysql_connect("localhost","username"); // Create an empty new variable.
mysql_select_db("test",$db);
$dvd_name=$POST['dvd_name'];
$query = "INSERT INTO dvds (dvd_name)
VALUES ('$dvd_name')";
$result = mysql_query($query);
}
?>
<form name="dvd_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"
onSubmit="return validate_form ( );">
<h1>Enter the DVD name</h1>
<p>Your Name: <input type="text" name="dvd_name"></p>
<p><input type="submit" name="send" value="Send Details"></p>
</form>
</body>
</html>