开发者

Cannot return from outside a function or method

开发者 https://www.devze.com 2023-04-04 14:05 出处:网络
I am getting an error saying \"Cannot return from outside a function or method\" near onsubmit=\"return validate()\"

I am getting an error saying "Cannot return from outside a function or method" near onsubmit="return validate()" whats wrong with the code plzzz help me got stuck....

chech this link for the file

<html>

<head>
<style>
body {
    margin: 0 auto;
    padding: 0px;
    background: white;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: black;
}

p {
    margin: 0px;
    padding: 0px;
}

#main-wraper {
    width: 756px;
    margin: 0 auto;
    padding: 0px;
}

#top-wraper {
    width: 756px;
    margin: 0 auto;
    float: left;
}

#banner {
    width: 1004px;
    float: center;
    background: url(banner22.jpg) top no-repeat;
    height: 100px;
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 35px;
    color: #fff;
    padding: 60px 0px 30px 120px;
}
</style>

<script type="text/javascript">
function validate()
{
    var valid=true;
    if (document.name1.username.value=="")
    {
        alert("please fill in the username");
        valid=false;
    }
    else if(document.name1.password.value=="")
    {
        alert("please enter the password");
        valid=false;
    }
return valid;
}
</script>

</head>

<body>
<form name="name1" action="Loginservlet" onsubmit="return validate()"
        method="post">
        <div id="banner">
            <center>
                <strong> NATIONAL SELF EMPLOYMENT </br> PROGRAM </strong>
            </center>
        </div>
        <center>
            <table>
                <tr><td>
                    </br></td>
                </tr>
                <tr><td>
                    </br></td>
                </tr>
                <tr><td>
                    </br></td>
                </tr>
                <tr align="center"><td>
                    <img src="image/UserLogin.jpg"> </td></td>
                </tr>

                <tr><td>
                    <fieldset>
                        <legend><b>NSEP Admin Login</b></legend>
                        <div align="center"></br> <font color="red"><b>Access Denied</b></font></div>
</br> Username:<input type="text" name="username" size="25"'
style="color:#0033FF;background-color:silver; border-style:dotted; border-width:1px;
border-color开发者_如何学编程:gray" /><br /></br>
Password: <input type="password" name="password" size="25" style="color:#0033FF;
background-color:silver; border-style:dotted; border-width:1px; border-color:gray" />
<br /></br>
<div>
    <center>
<input type="submit" value="Login" />
</center>
</div></fieldset></td></tr></table>
</center></form>
<p align="center"><font face="Arial" size="1" color="#336699">All Rights ® Reserved
</font></p>
</body>
</html>


Your example works fine in my Safari browser. My guess is that you're seeing some kind of bug in whatever browser you are using. (Let me guess IE6? IE7?)

Here's a simple thing that should work in all of those lousy IE legacy browsers:

  1. Remove onsubmit="return validate()" from the form.
  2. On line 61 (right after the end of the validate() function), add the following line:

    window.onload = function () {document.forms['name1'].onsubmit = validate;}

This is just a slightly more compatible way of setting up an event handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消