...

View Full Version : Validation



hcrosex3
11-30-2012, 09:02 PM
I'm not sure why this is not validating on blur. Any suggestions?



<!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>

WolfShade
11-30-2012, 09:14 PM
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.

Old Pedant
11-30-2012, 09:19 PM
Missing a left brace!


function setupEvents(evnt)
{
catchEvent(document.getElementById("txt"), "blur", validateField)
}

AndrewGSW
11-30-2012, 09:23 PM
It is important to get the heading of your page correct :rolleyes:

<h1> Rose Photgraphy</h1>

Old Pedant
11-30-2012, 09:23 PM
Also, what in the heck is this supposed to do?


window.onload= text;

You don't show any function named text( ) -- is there one?

Old Pedant
11-30-2012, 09:28 PM
Also, your validateField is needlessly complicated.

Try remembering to use this:


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

Old Pedant
11-30-2012, 09:29 PM
It is important to get the heading of your page correct :rolleyes:

<h1> Rose Photgraphy</h1>

LOL! Love it!

felgall
11-30-2012, 09:50 PM
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:

http://javascriptexample.net/inc/alert.gif

hcrosex3
11-30-2012, 09:50 PM
Missing a left brace!


function setupEvents(evnt)
{
catchEvent(document.getElementById("txt"), "blur", validateField)
}



It looks like this now but still no luck :(


<!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
11-30-2012, 09:52 PM
Also, what in the heck is this supposed to do?


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.

AndrewGSW
11-30-2012, 10:01 PM
You are missing braces ( ) for your function:


function validateField()
{

Old Pedant
11-30-2012, 10:22 PM
You are missing braces ( ) for your function:


function validateField()
{

Whoops! My fault! I should have caught that in his original and/or at least changed it in my rewrite.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum