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.
Page 3 of 3 FirstFirst 123
Results 31 to 45 of 45
  1. #31
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Philip,

    I've been trying to figure this out for a long *** time and you and jmrker have been great trying to walk me through this.

    Is there any way i could email you my file and you could take a look at it that way to prevent wasting more of your time?

  2. #32
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by hardhitter06 View Post
    Philip,

    I've been trying to figure this out for a long *** time and you and jmrker have been great trying to walk me through this.

    Is there any way i could email you my file and you could take a look at it that way to prevent wasting more of your time?
    Speaking for myself, I am sorry but I do not offer a free private coding service. I am happy to answer questions in the forum, but the real problem is that you do not have enough knowledge/experience to apply the information you have been given.

    One more time - have you tried using your error console?

    Have you tried placing alerts at strategic locations in the code to inspect the values or see whether a function is being executed?
    Last edited by Philip M; 11-26-2012 at 04:53 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #33
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    I have this:
    Code:
    function checkValidDate(which)  { 
    var s = which.replace(/[\-\s]/gi,"/");  // change hyphens or spaces to /
    var sp = s.split("/");
    var yr = sp[2];
    var mmx = sp[0];
    var dd = sp[1];
    
    alert(yr+' '+mmx+' '+dd);  // are you receiving what you expect?
    if (yr <1910 || yr >2012) { // you may want to change 2012 to some other year! 
    alert ("Year is out of range"); 
    return false;
    }
    
    mm = mmx-1; // remember that in Javascript date objects the months are 0-11 
    var nd = new Date(yr,mm,dd); // format YYYY,MM(0-11),DD 
    var ndmm = nd.getMonth(); 
    if (ndmm != mm) { 
    alert (dd + "/" + mmx + "/" + yr + " is an Invalid Date!"); 
    return false
    }
    else { 
    alert (dd + "/" + mmx + "/" + yr + " is a Valid Date"); 
    return true;  // return results of function to if statement
    } 
    }
    My javascript isnt being triggered with the extra code now...I've been looking through it and can't figure out why. Error console gives me no indication why.

  4. #34
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by hardhitter06 View Post
    I have this:
    Code:
    function checkValidDate(which)  { 
    var s = which.replace(/[\-\s]/gi,"/");  // change hyphens or spaces to /
    var sp = s.split("/");
    var yr = sp[2];
    var mmx = sp[0];
    var dd = sp[1];
    
    alert(yr+' '+mmx+' '+dd);  // are you receiving what you expect?
    if (yr <1910 || yr >2012) { // you may want to change 2012 to some other year! 
    alert ("Year is out of range"); 
    return false;
    }
    
    mm = mmx-1; // remember that in Javascript date objects the months are 0-11 
    var nd = new Date(yr,mm,dd); // format YYYY,MM(0-11),DD 
    var ndmm = nd.getMonth(); 
    if (ndmm != mm) { 
    alert (dd + "/" + mmx + "/" + yr + " is an Invalid Date!"); 
    return false
    }
    else { 
    alert (dd + "/" + mmx + "/" + yr + " is a Valid Date"); 
    return true;  // return results of function to if statement
    } 
    }
    My javascript isnt being triggered with the extra code now...I've been looking through it and can't figure out why. Error console gives me no indication why.


    What happened to

    ENTER DATE AS MM/DD/YYYY <input name="EffectiveDate." type="text" size="10" onblur = "checkValidDate(this.value)">

    The code I gave you works for me.

    In future you should show your (relevant) HTMLas well as your (relevant) Javascript.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  5. Users who have thanked Philip M for this post:

    hardhitter06 (11-27-2012)

  6. #35
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Code:
    function validateForm( frm )
    {
    	var oops = "";
    	var apptype = getRBValue( frm.elements["MoveType."] );
        if ( apptype == null )
            oops += "You must check Temporary or Permanent.\n";
    	var apptype = getRBValue( frm.elements["ResSummer."] );
        if ( apptype == null )
            oops += "You must check Yes or No for residential summer student.\n";
        if ( trim( frm.elements["FirstName."] ).length  < 2 )
            oops += "You must enter your First name.\n";
        if ( trim( frm.elements["LastName."] ).length  < 2 )
            oops += "You must enter your Last name.\n";
        if ( ! emailCheck( frm.elements["Email."] ) )
            oops += "That does not appear to be a valid Email Address.\n";
    	if (trim( frm.elements["Box."] ).length  < 1 || trim( frm.elements["Box."] ).length > 4)
            oops += "You must enter a Box# (Max 4 digits).\n";
        if ( ! checkValidDate( frm.elements["EffectiveDate."] ) )
            oops += "You must enter your Effective Date of Move in the proper format (MM/DD/YYYY).\n";	if ( trim( frm.elements["StreetAddress."] ).length  < 5 )
            oops += "You must enter your Street Address.\n";
    	if ( trim( frm.elements["City."] ).length  < 4 )
            oops += "You must enter your City.\n";
        if ( trim( frm.elements["State."] ).length  < 1 )
            oops += "You must enter your State.\n";
    	if ( ! zipCheck( frm.elements["Zip."] ) )
            oops += "You must enter a 5 digit Zip Code.\n";
        // additional building and room are not validated, but they are are trimmed and upper cased
        trim(frm.Apt);
    	
        
        var inps = frm.elements;
        var chkbx = false;
        for ( var i = 0; i < inps.length; ++i )
        {
            var inp = inps[i];
            if ( inp.name.indexOf("ChkBx") > 0 && inp.value != "" && inp.checked )
            {
                var chkbx = true;
                break;
            }
        }
    
    
        if ( oops == "" ) return true;
    	alert("ERROR(S):\n" + oops);    
        return false;
    }}
    Code:
      <td><input name="EffectiveDate." type="text" size="10" onblur = "checkValidDate(this.value)">
        <br>
          <em>Format: MM/DD/YYYY i.e. 01/0<font face="Times New Roman, Times, serif">1</font>/2012 </em></td>
    Haha I believe you Philip. This code is weird though - sometimes when I add new stuff even if there are no errors in it, it breaks my javascript validation.

    I've tried copying it all and putting the code in a fresh file but that isn't working either.

  7. #36
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,083
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    In EVERY ONE of your 'if...' statements, put in the associated braces {} to complete the logic.

    For example:
    Code:
        if ( ! checkValidDate( frm.elements["EffectiveDate."] ) )
            oops += "You must enter your Effective Date of Move in the proper format (MM/DD/YYYY).\n";	if ( trim( frm.elements["StreetAddress."] ).length  < 5 )
            oops += "You must enter your Street Address.\n";
    should be:
    Code:
        if ( ! checkValidDate( frm.elements["EffectiveDate."] ) ) {
            oops += "You must enter your Effective Date of Move in the proper format (MM/DD/YYYY).\n"; }
        if ( trim( frm.elements["StreetAddress."] ).length  < 5 ) {
            oops += "You must enter your Street Address.\n"; }
    This may not solve the problem, but it would make it infinitely easier to read and decide upon the status of each condition.

    Another thought:
    You should remove or rename each element with a '.' character from your element names and assignments.
    AFAIK, I don't think it is a valid character as there should be alpha-numeric and '_' characters only in the names.
    Last edited by jmrker; 11-27-2012 at 03:19 PM.

  8. Users who have thanked jmrker for this post:

    hardhitter06 (11-27-2012)

  9. #37
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Ok I put the {} around each "if" but my validation is still not triggering.

    There is something in the function checkValidDate that is screwing with my code. I'm sure Philip has the right code but for some reason it isn't meshing with my code properly. I can't even check if the date validation is working properly because the javascript as a whole isn't working.

    Regarding the "." in the field names, they are used with this "Form to File" set up for this HTML form so that if someone has javascript disabled on their web browser it will still trigger the fields that haven't been filled in.

    I removed the "." for effective date to eliminate that from being a possible issue.

  10. #38
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    i got excited and noticed one of the "return false" didnt have a following ";" but that didn't correct the problem.

    Also, I know we were using a couple of the alerts to check the code but I don't think any are needed in the function since my final function of validating the form alerts the users if a field hasn't been filled out properly. So Philips function purely needs to run the date through to check and see if it's an actual date. Then the final function will alert them in the returned date is incorrect...

    I may have worded that funny but I have the same type of set up for email check (which basically makes sure there is an @ in the email).

    Textbox for email:
    Code:
    <input name="Email." type="text" size="30">
    Function for email:
    Code:
    var echk = /^([a-z][\w\-\'\.]*)+\@([a-z][\w\-\'\.]+\.)+[a-z]{2,6}$/i
    function emailCheck( fld )
    {
        var email = trim( fld );
        fld.value = email;
        return echk.test(email);
    }
    Function ValidateForm that shows errors to end user:

    Code:
     
    function validateForm( frm )
    {
    var oops = "";
    if ( ! emailCheck( frm.elements["Email."] ) ) {
            oops += "That does not appear to be a valid Email Address.\n"; }
    
        if ( oops == "" ) return true;
    	alert("ERROR(S):\n" + oops);    
        return false;
    }
    [Just cut out the email field]

    So I need the EffectiveDate to follow the same process..I don't know if thats how Philip's code is currently set up to do that.
    Last edited by hardhitter06; 11-27-2012 at 04:18 PM.

  11. #39
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    I have to say that this is getting a little tedious.

    It seems likely (certain in fact if none of your Javascript works) that your code contains syntax errors which prevent the script from working. jmrker has pointed out . (periods) in names which are invalid. You must not use any punctuation marks of any kind in a JavaScript variable name, other than the underscore.

    You seem to be trying to doctor a validation script you have copied from somewhere without understanding any limitations which may apply.

    Show your (relevant) stripped down code relating to the date entry (only) - not other fields. Both HTML and Javascript. Don't confuse the issue with code for validating something else..

    It is far better IMO to alert the user to input errors as they arise rather than storing them up until the final validation.

    To check for a blank field (my script checks that the date entered is valid)

    Code:
    if (frm.elements["EffectiveDate."].value == "" ) {
    oops += "You must enter your Effective Date of Move"; 
    }
    Last edited by Philip M; 11-27-2012 at 05:18 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  12. Users who have thanked Philip M for this post:

    hardhitter06 (11-27-2012)

  13. #40
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Well the problem is my Javascript worked until I put your code in. You can say all you want about me not understanding this which is partially true but the fact of the matter is it worked until I added your DateValidate function. And I thought forums were intended to help people that don't have all of the knowledge. I made you aware in the early goings that I lack experience but I've been working hard to learn this stuff through the process of this thread so give me some credit .

    I previously had a Date validation that at least made sure it was in the right format (didn't check to make sure it was an actual date) and my javascript triggered sooooo not trying to be offensive but there is something in your code that is breaking the link to my ValidateForm function.

    Please ignore the periods in the names...they worked with them before and with this "Form to File" i need to have them. They are not the issue.

    I showed you the email check only to show you the process of how my functions are set up. Again, I don't need to alert the user if they filled out the wrong date when they are at the field, odds are this will be a rare error so showing them all of the errors when they click the submit button is fine.

    Here are the 3 pieces of code [Input field, your function, my function]

    Code:
     <input name="EffectiveDate" type="text" size="10" onblur="checkValidDate(this.value)">
    Code:
    function checkValidDate(which)  { 
    var s = which.replace(/[\-\s]/gi,"/");  // change hyphens or spaces to /
    var sp = s.split("/");
    var yr = sp[2];
    var mmx = sp[0];
    var dd = sp[1];
    
    if (yr <1910 || yr >2012) { // you may want to change 2012 to some other year! 
    return false;
    }
    
    mm = mmx-1; // remember that in Javascript date objects the months are 0-11 
    var nd = new Date(yr,mm,dd); // format YYYY,MM(0-11),DD 
    var ndmm = nd.getMonth(); 
    if (ndmm != mm) 
    { 
    alert (dd + "/" + mmx + "/" + yr + " is an Invalid Date!"); 
    return false;
    }
    else { 
    alert (dd + "/" + mmx + "/" + yr + " is a Valid Date"); 
    return true;  // return results of function to if statement
    } 
    }
    Code:
    function validateForm( frm )
    {
    	var oops = "";
    if ( ! checkValidDate( frm.elements["EffectiveDate"] ) ) {
            oops += "You must enter your Effective Date of Move in the proper format (MM/DD/YYYY).\n";}
    
      if ( oops == "" ) return true;
    	alert("ERROR(S):\n" + oops);    
        return false;
    }
    Full source code can be see here: http://www.albany.edu/~StuAddCh/index.html

  14. #41
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    The code I gave you (repeated here) works just fine for me. So the fault, dear Brutus, lies not in the stars ......

    Code:
    ENTER  DATE IN MM/DD/YYYY FORMAT <input name="EffectiveDate" type="text" size="10" onblur="checkValidDate(this.value)">
    
    <script type = "text/javascript">
    
    function checkValidDate(which)  { 
    var s = which.replace(/[\-\s]/gi,"/");  // change hyphens or spaces to /
    var sp = s.split("/");
    var yr = sp[2];
    var mmx = sp[0];
    var dd = sp[1];
    
    if (yr <1910 || yr >2012) { // you may want to change 2012 to some other year! 
    return false;
    }
    
    mm = mmx-1; // remember that in Javascript date objects the months are 0-11 
    var nd = new Date(yr,mm,dd); // format YYYY,MM(0-11),DD 
    var ndmm = nd.getMonth(); 
    if (ndmm != mm) 
    { 
    alert (dd + "/" + mmx + "/" + yr + " is an Invalid Date!"); 
    return false;
    }
    else { 
    alert (dd + "/" + mmx + "/" + yr + " is a Valid Date"); 
    return true;  // return results of function to if statement
    } 
    }
    </script>
    Your final validation only needs to check that a date entry (which if made must be a valid date) has been made. If not, (field is blank) trigger the message.

    Code:
    if (frm.elements["EffectiveDate."].value == "" ) {
    oops += "You must enter your Effective Date of Move"; 
    }
    The checkValidDate() function requires the value of the input field to be passed to it. Try:-

    if ( ! checkValidDate(frm.elements["EffectiveDate."].value ) ) {
    Last edited by Philip M; 11-27-2012 at 05:39 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  15. Users who have thanked Philip M for this post:

    hardhitter06 (11-27-2012)

  16. #42
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Why impose both separators and leading zeros?

    The leading zeros are made to remove the separator? Are they not ?

    You must allow dates as MMDDYYYY !

    Separators may allow the user to see clearly? So they must be left to his choice. Under these conditions, It should be possible to authorize the use of separators with or without leading zeros.

    Then a script could he not take this form?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <title></title>
    <style type="text/css">
    #pge {width:200px;}
    p{margin:3px auto;}
    input{display:block;margin:0 auto;text-align:center}
    </style>
    </head>
    <body>
    <div id="pge"><fieldset><legend>Enter a date</legend>
    <p><input id="dte" type="txt" onchange="tst()"></p>
    <p id="rsp">&nbsp;</p>
    </<fieldset></div>
    <script type="text/javascript">
    String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'')}
    
    function tst(){
    	var str=document.getElementById('dte').value, month, date, year;
    	var rgx=/0?([1-9]{1,2})[\D]*0?([1-9]{1,2})[\D]*([1-9]{4})/;
    	// A replace method with an anonymous function to define  month, date and year 
    	str.trim().replace(rgx,
    		function(all,b1,b2,b3){month=+b1;date=+b2;year=+b3;});
    	if (isNaN(month)||isNaN(date)||isNaN(year)) {document.getElementById('rsp').innerHTML='Please, enter a valid date with digits, separators or leading zeros (M/D/YYYY or MM/DD/YYYY)';return}
    	var dat=new Date(year, month-1, date);
    	if (dat.getMonth()!=month-1) {document.getElementById('rsp').innerHTML='Sorry, this date seems not valid !';return}
    	// If you insist absolutely on this redundant form. You write It !  
    	else document.getElementById('dte').value=(month<10?'0':'')+month+'/'+(date<10?'0':'')+date+'/'+year; 
    }
    </script>
    </body>
    </html>
    This function works with any separators, residual spaces or leading zeros !
    Last edited by 007julien; 11-27-2012 at 08:48 PM. Reason: cleaning and complements

  17. #43
    New Coder
    Join Date
    Jun 2009
    Posts
    95
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Philip/JMrker,

    This is weird but it finally worked!!!

    Philip, I made the change to the validate form piece of code and tested - javascript still didnt trigger. I then commented out everything that had to do with effectivedate and my validation triggered. I then only commented out Philips function and activated the piece in the validate form but still no javascript trigger. I then swapped that and allowed Philips function and commented out the piece in the validate form and the validation triggered. I then activated all of the code again and the freaking thing worked lol...go figure...

    Anyways I will provide the three pieces of code for anyone else who may find use with this. I want to thank you both a million times for the patience you had with me through this tedious mess lol...soo thanks!! have a great day guys.

    [Field code, Phillips DateValidate function, my ValidateForm function]

    Code:
    <input name="EffectiveDate" type="text" size="10" onBlur="checkValidDate(this.value)">
    Code:
    function checkValidDate(which)  { 
    var s = which.replace(/[\-\s]/gi,"/");  // change hyphens or spaces to /
    var sp = s.split("/");
    var yr = sp[2];
    var mmx = sp[0];
    var dd = sp[1];
    
    if (yr < 2012) { // you may want to change 2012 to some other year! 
    return false;
    }
    
    mm = mmx-1; // remember that in Javascript date objects the months are 0-11 
    var nd = new Date(yr,mm,dd); // format YYYY,MM(0-11),DD 
    var ndmm = nd.getMonth(); 
    if (ndmm != mm) 
    { 
    //alert (mmx+ "/" + dd + "/" + yr + " is an Invalid Date!"); 
    return false;
    }
    else { 
    //alert (mmx + "/" + dd + "/" + yr + " is a Valid Date"); 
    return true;  // return results of function to if statement
    } 
    }
    Code:
    function validateForm( frm )
    {
    	var oops = "";
       if ( ! checkValidDate(frm.elements["EffectiveDate"].value ) ) { 
            oops += "You must enter your Effective Date of Move. \n" ; }
        if ( oops == "" ) return true;
    	alert("ERROR(S):\n" + oops);    
        return false;
    }

  18. #44
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Glad to hear that you have got it working! I think that at some stage you introduced a syntax error when you commented out part of the code.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  19. #45
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts

    A regular expression to find...

    Sorry, I make a mistake with the regular expression. The right regular expression is to find ...

    EDIT : Perhaps this one which allow one digit followed by a separator or two digits for month and date
    Code:
    var rgx=/(\d(?=\D)|\d\d)[\D]*(\d(?=\D)|\d\d)[\D]*([0-9]{4})/;
    Last edited by 007julien; 11-28-2012 at 09:25 PM. Reason: errors...


 
Page 3 of 3 FirstFirst 123

Posting Permissions

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