Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Tuesday, 25 October 2011

Upload file extension restriction in jquery

Image upload field only accept following extension gif, png, jpg,jpeg.
<form action="" method="post" enctype="multipart/form-data">
Upload Image:<input type="file" name="image" id="image_id"  />
</form>
following code used to limit the upload file extension
<script type="text/javascript">
$(function() {
   $('#image_id').change( function() {
    var ext = $('#image_id').val().split('.').pop().toLowerCase();
    if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
      $('#image_id').val("");
        alert('Please Enter the files in the format jpeg,gif,png');
       
    }
   });
});
</script>

Tuesday, 27 September 2011

Hide after current date in jquery datepicker


If use date picker for Date of birth, need to hide after current date in date picker.
In jquery date picker maxDate is user to hide the dates after current date.

Assign maxDate to current date.

<script type="text/javascript">
<!--

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()

$(document).ready(function(){
    $('#DOB1').datepick({
    yearRange: '-90:+10',
    dateFormat: 'mm/dd/yyyy',
    maxDate: 'month/day/year',
    altField: '#DOB1_alt',
    showTrigger: '<img src="images/calendar.gif" alt="Popup" class="trigger">',
    onSelect: function(dates) {
        
    var date = dates[0];
    $('#DOB1_alt').val(date);
    }
    });
    });  

//-->
</script></div>