Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: Validation

  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    10
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,733
    Thanks
    80
    Thanked 4,516 Times in 4,480 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,733
    Thanks
    80
    Thanked 4,516 Times in 4,480 Posts
    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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,733
    Thanks
    80
    Thanked 4,516 Times in 4,480 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    hcrosex3 (11-30-2012)

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,733
    Thanks
    80
    Thanked 4,516 Times in 4,480 Posts
    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.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New Coder
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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>

  • #10
    New Coder
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.

  • #11
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • Users who have thanked AndrewGSW for this post:

    hcrosex3 (11-30-2012)

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,733
    Thanks
    80
    Thanked 4,516 Times in 4,480 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •