Php JavaScript突然停止工作
我的JavaScript正在工作,但现在不行了 这只是为了验证表单 我开始在应用程序上应用我的模板,似乎在某个时候它停止了…有什么想法可以做到这一点吗Php JavaScript突然停止工作,php,javascript,html,css,Php,Javascript,Html,Css,我的JavaScript正在工作,但现在不行了 这只是为了验证表单 我开始在应用程序上应用我的模板,似乎在某个时候它停止了…有什么想法可以做到这一点吗 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Create Profile</title> <meta http-equiv="Content-Type" c
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Create Profile</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css"href="style.css">
<script type="text/javascript">
function validateForm()
{
var firstName=document.forms["register"]["firstName"].value;
var lastName=document.forms["register"]["lastName"].value;
var UserName=document.forms["register"]["UserName"].value;
var Password=document.forms["register"]["Password"].value;
var description=document.forms["register"]["description"].value;
var DOB=document.forms["register"]["DOB"].value;
var likes=document.forms.register.elements['likes[]'];
var image=document.forms["register"]["image"].value;
var likesCheck = 0;
for (var i = 0; i < likes.length; i++)
{
if (likes[i].checked)
{
likesCheck++;
}
}
if (likesCheck == 0)
{
alert("likes must be selected");
return false;
}
if (firstName==null || firstName=="")
{
alert("First Name must be valid.");
return false;
}
else if (lastName==null || lastName=="")
{
alert("Last Name must be valid.");
return false;
}
else if (UserName==null || UserName=="")
{
alert("UserName must be valid.");
return false;
}
else if (DOB==null || DOB=="")
{
alert("DOB must be valid.");
return false;
}
else if (Password==null || Password=="")
{
alert("Password must be valid.");
return false;
}
else if (image==null || image=="")
{
alert("image must be valid.");
return false;
}
else if (description==null || description=="")
{
alert("description must be valid.");
return false;
}
}
</script>
</head>
<body>
<div id="container">
<div id="header">
<div class="title"><a href="index.php">The Griffith Dating Connection</a></div>
<div class="subtitle">find your "study buddy"</div>
<div class="intro-part1">Where Griffith singles meet.</div>
<div class="intro-part2"></div></div>
<div id="nav">
<div id="nav-in-top">
</div>
<div id="nav-in-middle">
<p class="title2">Navigation</p><br>
<span>
<a class="menu" href="index.php">Home</a>
<a class="menu" href="allusers.php">View All Users</a>
<a class="menu" href="doc.html">Documentation</a>
</span>
<p> </p>
</div>
<div id="nav-in-bottom"></div>
</div>
<div id="content">
<p class="title2"><b>Dating</b></p>
<br>
</div>
<div id="box">
<form name="register" method="post" action="profiles.php" onSubmit="return validateForm()" enctype="multipart/form-data" class="classform">
<table style="margin: 0 auto;" class="bordered">
<tr>
<td class="col1"> First Name </td>
<td class="col2"> <input type="text" name="firstName" size=30> </td>
</tr>
<tr>
<td class="col1"> Last Name </td>
<td class="col2"> <input type="text" name="lastName" size=30> </td>
</tr>
<tr>
<td class="col1"> Username </td>
<td class="col2"> <input type="text" name="UserName" size=30> </td>
</tr>
<tr>
<td class="col1">Password </td>
<td class="col2"> <input type="password" name="Password" size=30> </td>
</tr>
<tr>
<td class="col1"> Gender </td>
<td class="col2">
<input type="radio" name="gender" value="Male" checked>Male<br>
<input type="radio" name="gender" value="Female">Female<br>
</tr>
<tr>
<td class="col1"> Date of Birth </td>
<td class="col2"> <input name="DOB" type="text" value="YYYY/MM/DD" size=30> </td>
</tr>
<tr>
<td class="col1"> Email </td>
<td class="col2"> <input type="text" name="email" size=30> </td>
</tr>
<tr>
<td class="col1"> Description </td>
<td class="col2"> <textarea name="description" cols="60" rows="10"></textarea> </td>
</tr>
<tr>
<td class="col1"> Likes </td>
<td class="col2">
<input type="checkbox" name="likes[]" value="1">Swimming
<input type="checkbox" name="likes[]" value="2">Dancing
<input type="checkbox" name="likes[]" value="3">walking
<input type="checkbox" name="likes[]" value="4">making pizza
<input type="checkbox" name="likes[]" value="5">wrestling
<input type="checkbox" name="likes[]" value="6">ddddd
<input type="checkbox" name="likes[]" value="7">ddddd
<input type="checkbox" name="likes[]" value="8">ddddd
<input type="checkbox" name="likes[]" value="9">ddddd
<input type="checkbox" name="likes[]" value="10">sss
<input type="checkbox" name="likes[]" value="11">system
<input type="checkbox" name="likes[]" value="12">sysss
<input type="checkbox" name="likes[]" value="13">newer
<input type="checkbox" name="likes[]" value="14">newer
</td>
</tr>
<tr>
<td class="col1"> Create a new like</td>
<td class="col2">
<input type="text" name="newlike" size=30><br>
</td>
</tr>
<tr>
<td class="col1">Profile Picture</td>
<td class="col2">
<input type="file" name="file" id="file">
</td>
</tr>
<tr>
<td colspan=2 style="text-align: center">
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>
<div id="footer"> Josip Zirdum Griffith Student Number "s2794971" </div>
</div>
</body>
</html>
创建配置文件
函数validateForm()
{
var firstName=document.forms[“register”][“firstName”].value;
var lastName=document.forms[“register”][“lastName”].value;
var UserName=document.forms[“register”][“UserName”].value;
var Password=document.forms[“register”][“Password”]。值;
var description=document.forms[“register”][“description”]。值;
var DOB=document.forms[“register”][“DOB”]值;
var likes=document.forms.register.elements['likes[]'];
var image=document.forms[“register”][“image”].value;
var-likesCheck=0;
for(var i=0;i
约会
名字
姓
用户名
暗语
性别
男性
女性
出生日期
电子邮件
描述
喜欢
游泳
跳舞
行走
做比萨饼
摔跤
DDD
DDD
DDD
DDD
sss
系统
系统
更新的
更新的
创建一个新的
侧面图
Josip Zirdum Griffith学生编号“s2794971”
我得到这个错误:
我已经修好了。问题是我调用的是“image”,但我将表单元素命名为“file”。忘了我最近做过这件事。很抱歉浪费了你的时间。但是谢谢你的调试技巧:)我给你一个建议 你的javascript看起来还可以,但如果不可以,你应该使用Firefox扩展名firebug,为你的页面打开它,如果你有错误,它会显示错误,并帮助你进行web开发 你可以得到它
并且还添加了returntrue;在方法的末尾JS正在查找
说明
,但是表单控件名为说明
(可能还有其他错误,但这正是当前导致JS出错而不返回false的错误)
你在这里用大写字母D称呼它:
var Description=document.forms["register"]["Description"].value;
换成
var Description=document.forms["register"]["description"].value;
对于这样的问题,最好从“什么改变了?”开始,基本上就是添加模板。对我来说,onSubmit似乎不再在表单函数中工作……但不确定这意味着什么。它可能与添加触发标准模式的Doctype有关,这意味着您所犯的错误无法通过……但跟踪整个脚本将是一项乏味的工作。您在JS调试器中收到了什么错误消息?请定义“停止工作”-是否出错?如果是这样的话,JavaScript控制台工具,比如Chrome或FireFox w/Firebug中的那些工具,会说什么?@Matt:JavaScript控制台在FireFox中是本机可用的,你不必为此使用Firebug(尽管它是一个非常有价值的工具)。与其说是一个答案,不如说是一个评论,但还是一个合理的建议。为什么OP add
会返回true代码>?那没必要。此外,这应该是一个评论,而不是一个答案。正如我所看到的,这可以是答案,firebug wil
var Description=document.forms["register"]["description"].value;