Share it

Bookmark and Share

Translate

Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Thursday, July 3, 2014

1 No of days in a month validation


        function caldays(m,y)
        {
            if (m == 01 || m == 03 || m == 05 || m == 07 || m == 08 || m == 10 || m == 12)
            {
                return 31;             
            }
            else if (m == 04 || m == 06 || m == 09 || m == 11)
            {
                return 30;       
            }
            else
            {   
                if ((y % 4 == 0) || (y % 400 == 0 && y % 100 != 0))
                {   
                    return 29;         
                }
                else
                {
                    return 28;             
                }
            }   
        }


        /****No of days in a month validation*****/
        var sYear = jQuery("#yy-from").val();
        var sMonth = jQuery("#mm-from").val();
        var sDate = jQuery("#dd-from").val();
       
       
        var sMaxDate = caldays(sMonth,sYear);
        if(sDate > sMaxDate) {
           
            jQuery(".date-from-li .select2-choice").addClass('error');
        }
       
       
        var eYear = jQuery("#yy-to").val();
        var eMonth = jQuery("#mm-to").val();
        var eDate = jQuery("#dd-to").val();
       
        var eMaxDate = caldays(sMonth,sYear);
        if(eDate > eMaxDate) {
        jQuery(".date-to-li .select2-choice").addClass('error');
        }
        /*******end******/

Saturday, June 30, 2012

0 Javascript Form fields Validation


Download Source code:

 Steps


   1. Include gen_validatorv4.js in your html file just before closing the HEAD tag
      <script src="gen_validatorv4.js" type="text/javascript"></script>
      </head>
   2. Just after defining your form, create a Validator() object passing the name of the form
      <form id='myform' action="">
       <!----Your input fields go here -->
       </form>
       
      <script type="text/javascript">
       var frmvalidator  = new Validator("myform");
                           //where myform is the name/id of your form
   3. Now, add the validations required
      frmvalidator.addValidation("FirstName","req","Please enter your First Name");


      The format of the addValidation() function is:
      frmvalidator.addValidation(Field Name, Validation Descriptor, Error String);


      See below for the complete list of validation descriptors. The third parameter ( Error string ) is optional.
      You can add any number of validations to a field.
      frmvalidator.addValidation("FirstName","req","Please enter your First Name");
      frmvalidator.addValidation("FirstName","maxlen=40",
                                                "Max length for FirstName is 40");

Tuesday, September 20, 2011

0 Difference between return true; and return false; in JavaScript

When you are using return true or false with markup, you are indicating
whether or not you want the default action to happen after the javascript
has been executed. An example is needed:

<a href="somepage.html" onClick="alert('Hi'); return true;">Click Me</a>

When the link is clicked the javascript code for the onClick will run first,
and we get an alert. We have used return true, so that is saying when we
click OK to remove the alert, we do want to run the markup. So in this case
once we click OK to dismiss the alert, we would then be taken to
somepage.html. If we changed that to return false we would get the alert,
but wouldn't go to somepage.html.

0 Submit form automatically

This script submits the form automatically after 5 seconds
<html>
<head>
<SCRIPT LANGUAGE="JavaScript"><!--
setTimeout('document.test.submit()',5000);
//--></SCRIPT>

</head>

<body>
<form name="test" id="form1" method="post" action="http://www.php.net/search.php">
<p>
<input name="pattern" type="text" id="pattern" />
<input name="show" type="hidden" id="show" value="quickref" />
</p>
<p><input type="submit" name="next" value="Next" />
&nbsp; </p>
</form>
</body>
</html>


 

TechnoTipworld- Tips,Tricks,Technology Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates