Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-30-2012, 09:02 PM   PM User | #1
hcrosex3
New Coder

 
Join Date: Sep 2012
Posts: 32
Thanks: 10
Thanked 0 Times in 0 Posts
hcrosex3 is an unknown quantity at this point
Validation

I'm not sure why this is not validating on blur. Any suggestions?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">




<head>
<script type="text/javascript" src="fadeslideshow.js">
</script>

	  <link href="stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
  <link href="stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />
  <!--[if IE]>
      <link href="stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
  <![endif]-->
<link href='http://fonts.googleapis.com/css?family=Italianno' rel='stylesheet' type='text/css'>	


</head>

<script type="text/javascript">
window.onload= text;
var IdAry=['status1'];
</script>
<script type="text/javascript">
 
function catchEvent(eventObj, event, eventHandler) {
	if (eventObj.addEventListener) {
		eventObj.addEventListener(event, eventHandler, false);
	} else if (eventObj.attachEvent){
		event = "on" + event;
		eventObj.attachEvent(event, eventHandler);
	}
}
catchEvent(window,"load", setupEvents);

function setupEvents(evnt)
catchEvent(document.getElementById("txt"), "blur", validateField)
}
function validateField {
	var theEvent = evnt ? evnt : window.event;
	var target = theEvent.target ? theEvent.target : theEvent.srcElement;
	var rgEX = /^\d{2}[-]?\d{2}[-]?\d{3}$/g;

	var OK = rgEx.exec(target.value);
	if(!OK) {
		alert("not a vln");
	}
}


</script>




<body >
	<div id="header"> <h1> Rose Photgraphy</h1> </div>
	<div class="nav">
<ul>
<li><a href="index.htm" >Home</a></li>
<li><a href="gallery.htm">Gallery</a></li>
<li><a href="404.htm" >Contact</a></li>
<li><a href="404.htm">XML</a></li>
</ul>
</div>
<div id="login"> 
<form id="vln">
	Login: <input type="text|hidden" id="txt" >
</form>
</div>

	<div class='border-radius-example' id='border-radius'>
  <p id="status1">
<span id="span1">Find Out How I Got Into Photography!</span>
<span class="hide">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eu sapien eget justo porta posuere sollicitudin sed orci. Nunc dictum gravida elit, et sodales velit euismod sed. Nulla facilisi. Cras venenatis, libero ut varius adipiscing, mauris diam tristique eros, quis scelerisque justo enim pulvinar enim. Nulla ante mi, dictum et aliquam ut, interdum at leo. Ut imperdiet, mauris vel tempus euismod, purus nibh gravida urna, eget mattis ante mauris a libero. Maecenas malesuada sagittis justo et gravida. Pellentesque porttitor sollicitudin eleifend. Nulla facilisi. Maecenas feugiat laoreet orci, mattis tempus sem fermentum id. Aenean pretium blandit magna, ac ultrices turpis gravida eget. Proin at bibendum nisl. Phasellus aliquam, enim eu semper adipiscing, turpis lacus tristique nulla, tempor auctor magna odio in justo. Vestibulum vitae purus mauris. Morbi ornare enim sit amet ipsum volutpat a luctus metus condimentum. Quisque aliquet nunc et massa aliquam ut pulvinar justo gravida.

Sed sit amet elit nisl, vitae elementum magna. Phasellus metus dolor, scelerisque eu vulputate sit amet, lobortis et ante. Donec ac ultricies purus. Vivamus eget arcu sapien. Maecenas a orci at nulla luctus ullamcorper. Nulla scelerisque laoreet mollis. Proin sit amet enim ut mauris imperdiet aliquam eget vitae nulla. Duis non enim velit. Phasellus nisl lacus, malesuada eget luctus non, faucibus in mauris. Nunc condimentum, est eget luctus luctus, erat felis malesuada sem, in placerat tellus est vel arcu. Donec ligula erat, rhoncus ut cursus sed, volutpat a urna. Sed ultricies bibendum neque, a blandit velit varius ac. Duis orci nibh, tempor ac laoreet nec, aliquam eu turpis.

Pellentesque a orci arcu. Duis eget diam ac nulla pellentesque egestas. Suspendisse a nunc turpis. Cras dignissim aliquam dui, eu consequat mi venenatis at. Mauris non tellus a purus sollicitudin lobortis sit amet vitae velit. Nulla sit amet sodales ipsum. Nam leo dui, imperdiet et pharetra.</span>
</p>


</div>




</body>

</html>
hcrosex3 is offline   Reply With Quote
Old 11-30-2012, 09:14 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Not sure, but try removing the global variable from the RegEx. You're already using start of string and end of string in the mask.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 11-30-2012, 09:19 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Missing a left brace!
Code:
function setupEvents(evnt)
{
    catchEvent(document.getElementById("txt"), "blur", validateField)
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-30-2012, 09:23 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
It is important to get the heading of your page correct

<h1> Rose Photgraphy</h1>
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 11-30-2012, 09:23 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Also, what in the heck is this supposed to do?
Code:
window.onload= text;
You don't show any function named text( ) -- is there one?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-30-2012, 09:28 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Also, your validateField is needlessly complicated.

Try remembering to use this:
Code:
function validateField 
{
	var rgEX = /^\d{2}[-]?\d{2}[-]?\d{3}$/;
        if ( ! rgEX.test( this.value ) )
        {
		alert("not a vln");
	}
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
hcrosex3 (11-30-2012)
Old 11-30-2012, 09:29 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by AndrewGSW View Post
It is important to get the heading of your page correct

<h1> Rose Photgraphy</h1>
LOL! Love it!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-30-2012, 09:50 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,468
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Of course the debugging alert needs to be replaced by the actual code to display the message in the page before it goes live as you don't want visitors using the checkbox it displays in some browsers to turn off JavaScript on your page. For example this is how alerts appear in one browser:

__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-30-2012, 09:50 PM   PM User | #9
hcrosex3
New Coder

 
Join Date: Sep 2012
Posts: 32
Thanks: 10
Thanked 0 Times in 0 Posts
hcrosex3 is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Missing a left brace!
Code:
function setupEvents(evnt)
{
    catchEvent(document.getElementById("txt"), "blur", validateField)
}

It looks like this now but still no luck

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">




<head>
<script type="text/javascript" src="fadeslideshow.js">
</script>

	  <link href="stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
  <link href="stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />
  <!--[if IE]>
      <link href="stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
  <![endif]-->
<link href='http://fonts.googleapis.com/css?family=Italianno' rel='stylesheet' type='text/css'>	


</head>

<script type="text/javascript">
window.onload= text;
var IdAry=['status1'];
</script>
<script type="text/javascript">
 
function catchEvent(eventObj, event, eventHandler) {
	if (eventObj.addEventListener) {
		eventObj.addEventListener(event, eventHandler, false);
	} else if (eventObj.attachEvent){
		event = "on" + event;
		eventObj.attachEvent(event, eventHandler);
	}
}
catchEvent(window,"load", setupEvents);

function setupEvents(evnt)
{
catchEvent(document.getElementById("txt"), "blur", validateField)
}
 function validateField 
{
	var rgEX = /^\d{2}[-]?\d{2}[-]?\d{3}$/;
        if ( ! rgEX.test( this.value ) )
        {
		alert("not a vln");
	}
}


</script>




<body >
	<div id="header"> <h1> Rose Photography</h1> </div>
	<div class="nav">
<ul>
<li><a href="index.htm" >Home</a></li>
<li><a href="gallery.htm">Gallery</a></li>
<li><a href="404.htm" >Contact</a></li>
<li><a href="404.htm">XML</a></li>
</ul>
</div>
<div id="login"> 
<form id="vln">
	Login: <input type="text|hidden" id="txt" >
</form>
</div>

	<div class='border-radius-example' id='border-radius'>
  <p id="status1">
<span id="span1">Find Out How I Got Into Photography!</span>
<span class="hide">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eu sapien eget justo porta posuere sollicitudin sed orci. Nunc dictum gravida elit, et sodales velit euismod sed. Nulla facilisi. Cras venenatis, libero ut varius adipiscing, mauris diam tristique eros, quis scelerisque justo enim pulvinar enim. Nulla ante mi, dictum et aliquam ut, interdum at leo. Ut imperdiet, mauris vel tempus euismod, purus nibh gravida urna, eget mattis ante mauris a libero. Maecenas malesuada sagittis justo et gravida. Pellentesque porttitor sollicitudin eleifend. Nulla facilisi. Maecenas feugiat laoreet orci, mattis tempus sem fermentum id. Aenean pretium blandit magna, ac ultrices turpis gravida eget. Proin at bibendum nisl. Phasellus aliquam, enim eu semper adipiscing, turpis lacus tristique nulla, tempor auctor magna odio in justo. Vestibulum vitae purus mauris. Morbi ornare enim sit amet ipsum volutpat a luctus metus condimentum. Quisque aliquet nunc et massa aliquam ut pulvinar justo gravida.

Sed sit amet elit nisl, vitae elementum magna. Phasellus metus dolor, scelerisque eu vulputate sit amet, lobortis et ante. Donec ac ultricies purus. Vivamus eget arcu sapien. Maecenas a orci at nulla luctus ullamcorper. Nulla scelerisque laoreet mollis. Proin sit amet enim ut mauris imperdiet aliquam eget vitae nulla. Duis non enim velit. Phasellus nisl lacus, malesuada eget luctus non, faucibus in mauris. Nunc condimentum, est eget luctus luctus, erat felis malesuada sem, in placerat tellus est vel arcu. Donec ligula erat, rhoncus ut cursus sed, volutpat a urna. Sed ultricies bibendum neque, a blandit velit varius ac. Duis orci nibh, tempor ac laoreet nec, aliquam eu turpis.

Pellentesque a orci arcu. Duis eget diam ac nulla pellentesque egestas. Suspendisse a nunc turpis. Cras dignissim aliquam dui, eu consequat mi venenatis at. Mauris non tellus a purus sollicitudin lobortis sit amet vitae velit. Nulla sit amet sodales ipsum. Nam leo dui, imperdiet et pharetra.</span>
</p>


</div>




</body>

</html>
hcrosex3 is offline   Reply With Quote
Old 11-30-2012, 09:52 PM   PM User | #10
hcrosex3
New Coder

 
Join Date: Sep 2012
Posts: 32
Thanks: 10
Thanked 0 Times in 0 Posts
hcrosex3 is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Also, what in the heck is this supposed to do?
Code:
window.onload= text;
You don't show any function named text( ) -- is there one?
theres an extensive external js file for the rest of the site :x text controls whats in the div when paired with everything else.
hcrosex3 is offline   Reply With Quote
Old 11-30-2012, 10:01 PM   PM User | #11
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
You are missing braces ( ) for your function:

Code:
function validateField()
{
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
hcrosex3 (11-30-2012)
Old 11-30-2012, 10:22 PM   PM User | #12
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by AndrewGSW View Post
You are missing braces ( ) for your function:

Code:
function validateField()
{
Whoops! My fault! I should have caught that in his original and/or at least changed it in my rewrite.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:55 AM.


Advertisement
Log in to turn off these ads.