Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

onBlur function not working

Posted on 2011-02-21
2
Medium Priority
?
373 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:doRodrigo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34946722
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 34946744
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question