我正在编写一些PHP中包含以下javascript。问题是它不起作用,开发人员工具一直在说"' validate_entry'未定义"但我不知道自己在做什么
我的代码是:
<script type="text/javascript">
function validate_entry()
{
var name=document.getElementById("submitted").value;
var system=document.getElementById("system").value;
var details=document.getElementById("description").value;
if(name.trim() == "")
{
alert("The name you entered is too short");
return false;
}
if(name.length > 64)
{
alert("The name you entered is too long");
return false;
}
if(system.trim() == ""
{
alert("System is not valid");
return false;
}
if(details == "")
{
alert("Description cannot be empty");
return false;
}
}
</script>
我有以下表格:
<form action="index.php" method="POST" onsubmit="return validate_entry();">
<table>
<tr>
<td><label for="submitted">Issue Submitted By</label></td>
<td><input type="text" name="submitted" id="submitted" tabindex="<?php echo $header[0]++; ?>"></td>
</tr>
<tr>
<?php $systems = get_system_names($connection);
if($systems==FALSE)
{
echo "<td></td>\n";
echo "<td></td>\n";
}
else
{
echo "<td><label for=\"system\">System Name</label></td>\n";
echo "<td><select name=\"system\" id=\"system\" tabinex=\"". $header[0]++. "\">\n";
echo "<option>Please Select</option>\n";
foreach($systems as $system)
{
echo "<option value=\"{$system[0]}\">{$system[1]}</option>\n";
}
echo "</select></td>\n";
}
?>
</tr>
<tr>
<td><label for="description">Issue Description</label></td>
<td><textarea name="description" id="description" tabindex="<?php echo $header[0]++; ?>"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" id="submit" tabindex="<?php echo $header[0]++; ?>"></td>
</tr>
</table>
<?php echo "</form>\n";
答案 0 :(得分:1)