admin管理员组

文章数量:1330156

My JavaScript was working and now it's not.

It's just to validate the form

I started applying my template on the application and it seems at some point it just stopped...any ideas what could have done this?

<!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 &quot;study buddy&quot;</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>&nbsp;</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 &quot;s2794971&quot; </div> 
</div> 
</body> 
</html> 

I am getting this error:

I have fixed it. The problem was I was calling for "image" but I named the form element "file". Forgot I did this recently. Sorry for kind of wasting your time. But thanks for the debugging tricks :)

My JavaScript was working and now it's not.

It's just to validate the form

I started applying my template on the application and it seems at some point it just stopped...any ideas what could have done this?

<!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 &quot;study buddy&quot;</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>&nbsp;</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 &quot;s2794971&quot; </div> 
</div> 
</body> 
</html> 

I am getting this error:

I have fixed it. The problem was I was calling for "image" but I named the form element "file". Forgot I did this recently. Sorry for kind of wasting your time. But thanks for the debugging tricks :)

Share Improve this question edited May 23, 2011 at 14:43 Josip Gòdly Zirdum asked May 23, 2011 at 14:26 Josip Gòdly ZirdumJosip Gòdly Zirdum 7172 gold badges11 silver badges26 bronze badges 10
  • 4 With problems like these, the best place to start is 'what changed?' – Amy Anuszewski Commented May 23, 2011 at 14:28
  • Pretty much adding the template. to me it seems onSubmit no longer works in the form function...not sure what that would mean however. – Josip Gòdly Zirdum Commented May 23, 2011 at 14:29
  • It's probably going to be something to do with adding a Doctype that triggers standards mode means that an error you made isn't being let through … but tracking through that entire script is going to be a tedious job. What error message do you get in your JS debugger? – Quentin Commented May 23, 2011 at 14:29
  • 4 please define 'stopped working' - does it error out? if so, what does a JavaScript console tool, such as those found in Chrome or FireFox w/ Firebug say? – Matt Commented May 23, 2011 at 14:30
  • @Matt: the JavaScript console is natively available in Firefox, you don't have to use Firebug for that (though it's a very valuable tool). – Marcel Korpel Commented May 23, 2011 at 14:32
 |  Show 5 more ments

3 Answers 3

Reset to default 6

Your JS is looking for Description but your form control is named description.

(There may be other errors, but that is the one that is currently causing the JS to bug out and not return false)

Error: document.forms.register.Description is undefined

You are calling it here - with capital D:

var Description=document.forms["register"]["Description"].value;

Change it to

var Description=document.forms["register"]["description"].value;

I will give you one advice,

your javascript looks ok but you should use if you are not, Firefox extension called firebug, turn it on for your page and it will show you errors if you have any and will help you with web development.

You can get it http://getfirebug./

and also add return true; at the end of your methods

本文标签: phpJavaScript suddenly stopped workingStack Overflow