JavaScript Input Type Date validation 18 years old below input type date format,input type date html,input type

I'm having trouble with validation of input type="date". It shouldn't accept 18 years old below. Could you please help me? Thank you.

I google and search the forum I haven't found the answer. I tried to validate it in the next page using PHP but my professor told me I must validate it in the same page. Like onchange it must be validated.

<input type="date" name="bday" id="bday" value="">
Answer:1

make use of javascript. If you want to accept birthdate of only 18 years and above then try following javascript code. put onblur="return dobcheck()" in bday tag.

<script type="text/javascript">
function dobcheck()
{
    var birth = document.getElementById('bday')
    if(birth != "")
    {

        var record=document.getElementById('bday').value.trim();
        var currentdate=new Date();    
        var day1 = currentdate3.getDate();   
        var month1 = currentdate3.getMonth();
        month1++;     
        var year11 = currentdate3.getFullYear()-17;
        var year2= currentdate3.getFullYear()-100;   
        var record_day1=record.split("/");
        var sum=record_day1[1]+'/'+record_day1[0]+'/'+record_day1[2];  
        var current= month1+'/'+day1+'/'+year11;
        var current1= month1+'/'+day1+'/'+year2;
        var d1=new Date(current)
        var d2=new Date(current1)
        var record1 = new Date(sum);      
        if(record1 > d1)
        {

            alert("Sorry ! Minors need parential guidance to use this website");
            document.getElementById('bday').blur();
            document.getElementById('bday').value="";
            document.getElementById('bday').focus();
            return false;
        }
    } 
}
</script>

i hope that now you will get it...

Answer:2

In case you are allowed to use HTML5, it is pretty simple. You can simply use the max attribute:

<input id="bday" type="date" max="1995-12-31" required="" />

In case you have to do it dynamic you can create the max attribute dynamically.

I made an example: http://jsfiddle.net/trixta/wpb54/ http://jsfiddle.net/trixta/wpb54/4/

Answer:3

I'm trying to get href value of a specific anchor tag placed on a html page. html tag structure <a rel="nofollow" title="some title" href="http://www.this-is-what-i-need.com/just-this.html">&...

I'm trying to get href value of a specific anchor tag placed on a html page. html tag structure <a rel="nofollow" title="some title" href="http://www.this-is-what-i-need.com/just-this.html">&...

I've added a click event to a parent #carousel-thumbs. carouselThumbsContainer.onclick = function(ev) { var target = ev.target; // which child was actually clicked } <ul id="carousel-...

I've added a click event to a parent #carousel-thumbs. carouselThumbsContainer.onclick = function(ev) { var target = ev.target; // which child was actually clicked } <ul id="carousel-...

  1. javascript index child
  2. javascript child index in parent
  3. javascript index of child element
  4. javascript index of child node
  5. javascript get child index
  6. javascript getchild index in parent
  7. javascript find child index
  8. javascript dom child index
  9. javascript set child index
  10. javascript get index of child element
  11. javascript get index of child node
  12. javascript dom get child index
  13. javascript find index of child element

Let's say we have a ball that can be moved left and right around the screen. When you click space, the ball should jump. I got the ball to move left and right in a canvas. However, when the ball is ...

Let's say we have a ball that can be moved left and right around the screen. When you click space, the ball should jump. I got the ball to move left and right in a canvas. However, when the ball is ...

I am unable to append values into the _summary class or any other. I believe its a really simple syntax error I am making. I have been trying different syntax's for the past day, with no luck. I am ...

I am unable to append values into the _summary class or any other. I believe its a really simple syntax error I am making. I have been trying different syntax's for the past day, with no luck. I am ...

  1. append event jquery
  2. append event
  3. append event listener
  4. append event javascript
  5. append event listener jquery
  6. append event handler jquery
  7. append event onclick
  8. append event handler c#