laravel 5 - How to perform only javascript onClick and not PHP action on submitting a form -
i making form through laravel in want accept future dates.i validating date via javascript , popping alert when past date entered problem after alert going form action url (that form submitted) if past date entered. want remain page itself. please help.
<html> <script type="text/javascript"> function func() { var aa = document.getelementbyid('in').value; var bb=new date(); var y=aa.slice(0,4); var m=aa.slice(5,7); var d=aa.slice(8,10); if((y>=bb.getfullyear() && m>=(bb.getmonth()+1) && d>=bb.getdate())!=1) { alert('enter future date'); } } </script> <body> <form action="/submitted" method="post"> <input id="in" type="date" name="sdate"> <input type="submit" onclick="func()"></form> </body> </html>
use "return false;" after "alert();" command.
if((y>=bb.getfullyear() && m>=(bb.getmonth()+1) && d>=bb.getdate())!=1) { alert('enter future date'); return false; }
Comments
Post a Comment