onBlur function not working

Hi folks, I'm trying to make a function be called from the onBlur of a text field, I had it working on another html file but I can't make it work in this script and I can't find out why...

Any help would be great.

Code welcome.

My script is attached bellow.

 
<html><head>
<link rel="shortcut icon" href="http://www.r76.com.br/favicon.ico" type="image/x-icon/" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>R76 :: Sistemas para Internet :: Modulo Promo&ccedil;&atilde;o</title>
<link href="files/style.css" type="text/css" rel="stylesheet">
<link href="files/style_002.css" type="text/css" rel="stylesheet">
<link href="files/style_003.css" type="text/css" rel="stylesheet">
<link href="files/styles.css" type="text/css" rel="stylesheet">
<link href="files/template_styles.css" type="text/css" rel="stylesheet">

<style type="text/css">
<!--
.style3 {color: #666666}
a:link {
	color: #FFFFFF;
}
a:visited {
	color: #FFFFFF;
}
a:hover {
	color: #FFFFFF;
}
a:active {
	color: #FFFFFF;
}
-->
</style>
<script language="javascript">
	function VerificaCPF () {
		if (vercpf(document.frmcpf.cpf.value)) 
		{document.frmcpf.submit();}else 
		{errors="1";if (errors) alert('CPF NÃO VÁLIDO');
		document.retorno = (errors == '');}
		}
	function vercpf (cpf) {
		if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
		add = 0;
		for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
		rev = 0;
		if (rev != parseInt(cpf.charAt(9)))
		return false;
		add = 0;
		for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
		rev = 0;
		if (rev != parseInt(cpf.charAt(10)))
		return false;
		}
</script>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<div id="panel"></div>
<table id="table1" bgcolor="#ececec" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<tbody>

<tr>
<td valign="top">
<p>&nbsp;</p>
<table bgcolor="#ececec" border="0" cellpadding="0" cellspacing="0" width="100%">
	<tbody><tr>
		<td rowspan="5" bgcolor="#ececec" width="50"></td>
		<td bgcolor="#ececec" height="0"></td>
		<td rowspan="5" bgcolor="#ececec" width="50"></td>
	</tr>
	<tr>
		<td>
		<table align="center" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="970px">
			<tbody><tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0" width="100%">
					<tbody><tr>
						<td width="23">
						<img src="files/shade_corner_top_left.jpg" border="0" height="23" width="23"></td>
						<td background="files/shade_top.jpg">
						<p align="right">
						<img src="files/ban_2.jpg" border="0" height="23" width="495"></p></td>
						<td width="23">
						<img src="files/shade_corner_top_right.jpg" border="0" height="23" width="23"></td>
					</tr>
				</tbody></table>
				</td>
			</tr>
			<tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0" width="100%">
					<tbody>
				</tbody></table>
				</td>
			</tr>
			<tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
					<tbody><tr height="27">
						<td width="10"><img src="files/shade_left.jpg" border="0" height="220" width="10"></td>
						<td><div align="center">
						  <form name="form1" method="post" action="">
						    <p>&nbsp;</p>
						    <p>Cadastro da Promo&ccedil;&atilde;o de Reformula&ccedil;&atilde;o da R&aacute;dio</p>
						    <table width="70%" border="0">
                              <tr>
                                <td colspan="3"><div align="center">
                                  <table width="70%" border="0">
                                    <tr>
                                      <td width="47%"><div align="right">Nome:</div></td>
                                      <td width="4%"><div align="center"></div></td>
                                      <td width="49%"><div align="left">
                                        <input type="text" name="nome" id="nome">
                                      </div></td>
                                    </tr>
                                    <tr>
                                      <td><div align="right">Email:</div></td>
                                      <td><div align="center"></div></td>
                                      <td><div align="left">
                                        <input type="text" name="email" id="email">
                                      </div></td>
                                    </tr>
                                    <tr>
                                      <td><div align="right">CPF:</div></td>
                                      <td><div align="center"></div></td>
                                      <td><div align="left">
                                        <input type="text" name="cpf" size="12" maxlength="11" onBlur="VerificaCPF(this.value)">
                                      </div></td>
                                    </tr>
                                    <tr>
                                      <td><div align="right"></div></td>
                                      <td><div align="center"></div></td>
                                      <td><div align="left"></div></td>
                                    </tr>
                                    <tr>
                                      <td><div align="right"></div></td>
                                      <td><div align="center"></div></td>
                                      <td><div align="left"></div></td>
                                    </tr>
                                  </table>
                                </div>                                  <div align="center"></div>                                  <div align="center"></div>
                                  <div align="center"></div>
                                  <div align="center"></div>                                  <div align="center"></div>
                                  <div align="center"></div>
                                  <div align="center"></div>                                  <div align="center"></div>
                                  <div align="center"></div>
                                  <div align="center"></div>                                  <div align="center"></div></td>
                                </tr>
                              
                              <tr>
                                <td><div align="center"></div></td>
                                <td><div align="center">
                                  <input type="submit" name="button" id="button" value="Submit">
                                </div></td>
                                <td><div align="center"></div></td>
                              </tr>
                            </table>
                                  </form>
						  </div></td>
						<td background="files/shade_right.jpg" width="23"></td>
					</tr>
					<tr>
						<td background="files/shade_left.jpg" width="10"><img src="files/shade_left.jpg" border="0" height="1" width="10"></td>
						<td><div align="center"></div></td>
						<td background="files/shade_right.jpg" valign="bottom" width="23"></td>
					</tr>
				</tbody></table>
				</td>
			</tr>
			<tr width="970px">
				<td border="0" align="center" bgcolor="#ffffff">
					<table border="0" cellpadding="0" cellspacing="0" height="35px" width="100%">
						<tbody><tr valign="bottom">
							<td align="left" background="files/shade_left.jpg" valign="bottom" width="10"></td>
							<td height="100"></td>
							<td background="files/shade_right.jpg" valign="bottom" width="23">
								<img src="files/ban_down_4.jpg" width="23" height="100" border="0"></td>
						</tr>
					</tbody></table>
				</td>
			</tr>
			<tr>
				<td>
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
						<tbody><tr>
							<td width="23"><img src="files/shade_corner_down_left.jpg" border="0" height="23" width="23"></td>
							<td background="files/shade_down.jpg" width="100%">
								<p align="right"><img src="files/ban_down_3.jpg" border="0"></p></td>
							<td height="23" width="23"><img src="files/shade_corner_down_right.jpg" border="0" height="23" width="23"></td>
						</tr>
					</tbody></table>
				</td>
			</tr>
			
			
			
			
			
		</tbody></table>
		</td>
	</tr>
	<tr>
		<td bgcolor="#ececec" height="50"></td>
	</tr>
</tbody></table>
</td>
	</tr>
</tbody></table>

<script src="files/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-221638-3";
urchinTracker();
</script>

</body></html>

Open in new window

doRodrigoAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Firefox Error Console says 'document.frmcpf.cpf' is not defined after 'onblur'.  The name of your form is 'form1'.  Is it supposed to be something else?  It works if you name your form 'frmcpf'.
0
 
sjklein42Commented:
It IS working but:

line 30:  if (vercpf(document.frmcpf.cpf.value))

is throwing an exception:

document.frmcpf.cpf is null or not an object
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.