Link to home
Start Free TrialLog in
Avatar of khaleghi
khaleghi

asked on

Why JavaScript codes stopped working?

I have a register page in my website where people can register before logging in.
I have built this page with ASP and by using JavaScript it should not allow user to leave any filed empty or type an invalid email address
it was working fine but suddenly stopped working
can anyone tell me where is the problem
many thanks
these are my page and codes
http://www.narjesbanoo.com/Register.asp

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/NBconnect.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
  MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

// boolean to abort record edit
var MM_abortEdit = false;
%>
<%
if (String(Request("MM_insert")) == "form1") {
  if (!MM_abortEdit) {
    // execute the insert
	
    var MM_editCmd = Server.CreateObject ("ADODB.Command");
    MM_editCmd.ActiveConnection = MM_NBconnect_STRING;
    MM_editCmd.CommandText = "INSERT INTO dbo.Login (FirstName, Surename, Relation, email, Username, Password) VALUES (?, ?, ?, ?, ?, ?)";
    MM_editCmd.Prepared = true;
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param1", 202, 1, 15, Request.Form("FirstName"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param2", 202, 1, 20, Request.Form("Surename"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", 202, 1, 20, Request.Form("Relation"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param4", 202, 1, 50, Request.Form("email"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param5", 202, 1, 15, Request.Form("Username"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param6", 202, 1, 15, Request.Form("Password"))); // adVarWChar
    MM_editCmd.Execute();
    MM_editCmd.ActiveConnection.Close();

    // append the query string to the redirect URL
    var MM_editRedirectUrl = "index.asp";
    if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
      MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1) ? "?" : "&") + Request.QueryString;
    }
    Response.Redirect(MM_editRedirectUrl)
  }
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>¿¿¿ ¿¿¿</title>
<script type="text/javascript"> 
function validate_required(field,alerttxt,condition)
{
        if( typeof(condition)=="undefined" )
        {
                condition="empty";
        }
        with (field)
        {
                if (name=='Name' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
				else if (name=='Surename' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
				else if (name=='Relation' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
				else if (name=='email' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
                else if (name=='email' && condition=='format' && (false==/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/i.test(value)) )
                {
                        alert(alerttxt);
                        return false;
                }
                else if (name=='Username' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
				else if (name=='Password' && condition=='empty' && (value==null||value=="") )
                {
                        alert(alerttxt);
                        return false;
                }
        }
return true;
}
 
function validate_form(thisform)
{
        with (thisform)
        {
                if (validate_required(Name,"Please fill in the 'Name' box.¿¿¿¿ ¿¿¿ ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿ ¿ ¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿ ¿¿¿¿")==false)
                {
                        Name.focus();
                        return false;
                }
				else if (validate_required(Surename,"Please fill in the 'Surename' box.¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿ 15 ¿¿¿ ¿¿¿¿¿ ¿¿¿¿")==false)
                {
                        Surename.focus();
                        return false;
                }
				else if (validate_required(Relation,"Please fill in the 'Relation' box.¿¿¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿ ¿ ¿¿¿¿ ¿¿¿ ¿¿¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿ ¿¿ ¿¿¿¿")==false)
                {
                        Relation.focus();
                        return false;
                }
				else if (validate_required(email,"Please fill in the 'Email' box.¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿ ¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿")==false)
                {
                        email.focus();
                        return false;
                }
                else if (validate_required(email,"Email address is not valid!¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿ ¿¿¿ ¿¿ ¿¿¿¿ ¿¿¿¿ ¿¿¿¿¿¿¿",'format')==false)
                {
                        email.focus();
                        return false;
                }
                else if (validate_required(Username,"Please fill in the 'Username' box.¿¿¿¿ ¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿")==false)
                {
                        Username.focus();
                        return false;
                }
                else if (validate_required(Password,"Please fill in the 'Password' box.¿¿¿¿ ¿¿ ¿¿¿¿¿¿¿ ¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿")==false)
                {
                        Password.focus();
                        return false;
                }
        }
return true;
}
</script>
<style type="text/css">
<!--
body {
	font: 100% Verdana, Arial, Helvetica, sans-serif;
	background: #666666;
	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
	padding: 0;
	text-align: center;
	background-image: url(image/Bg1.jpg);
}

.oneColFixCtr #container {
	width: 850px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
	background: #FFFFFF;
	margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
	border: 0px solid #000000;
	text-align: left; /* this overrides the text-align: center on the body element. */
	background-image: url(image/Bg25.jpg);
	background-repeat: no-repeat;
}
.oneColFixCtr #mainContent {
	padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
-->
</style></head>

<body class="oneColFixCtr">

<div id="container"><table width="850" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="111" colspan="4">&nbsp;</td>
      </tr>
      <tr>
        <td width="39" height="100">&nbsp;</td>
        <td width="572" align="right" valign="bottom"><p><img src="image/Text1.png" width="226" height="60" /></p>
        <p><a href="mailto:narjesbanoo@googlemail.com"><img src="image/text2-2.png" width="63" height="60" border="0" /></a><img src="image/Text2.png" width="237" height="60" /></p></td>
        <td width="190">&nbsp;</td>
        <td width="49">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td height="500" colspan="2" align="center" valign="top">&nbsp;
        <form action="<%=MM_editAction%>" method="post" name="form1" id="form1" onsubmit="return validate_form(this)">
          <table align="center">
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">FirstName:</td>
              <td valign="middle"><input name="FirstName" type="text" value="" size="20" maxlength="15" /></td>
              <td align="right"><img src="image/Text3.png" width="23" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">Surename:</td>
              <td valign="middle"><input name="Surename" type="text" value="" size="20" maxlength="20" /></td>
              <td align="right"><img src="image/Text4.png" width="62" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">Relation:</td>
              <td valign="middle"><input name="Relation" type="text" size="20" maxlength="20" /></td>
              <td align="right"><img src="image/Text5.png" width="94" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">Email:</td>
              <td valign="middle"><input name="email" type="text" value="" size="20" maxlength="50" /></td>
              <td align="right"><img src="image/Text6.png" width="93" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">Username:</td>
              <td valign="middle"><input name="Username" type="text" value="" size="20" maxlength="15" /></td>
              <td align="right"><img src="image/Text7.png" width="69" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">Password:</td>
              <td valign="middle"><input name="Password" type="text" value="" size="20" maxlength="15" /></td>
              <td align="right"><img src="image/Text8.png" width="43" height="45" /></td>
            </tr>
            <tr valign="baseline">
              <td align="left" valign="middle" nowrap="nowrap">&nbsp;</td>
              <td valign="middle"><input type="submit" value="¿¿¿ ¿¿¿¿ ¿¿" /></td>
              <td align="right">&nbsp;</td>
            </tr>
          </table>
          <input type="hidden" name="MM_insert" value="form1" />
        </form>
        <p>&nbsp;</p></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
</table></div>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tobzzz
tobzzz
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of khaleghi
khaleghi

ASKER

Thanks so much
It's not hard to believe how careless can I be
yes my code had a funny mistake and your codes are working perfect
you're brilliant.
Pleased to help and it's a very easy mistake to make. If I could count the hours I've sat staring at broken code only to find I was missing one character such as an apostrophe! Good luck with the project.

/ Tobzzz