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

Friday, 15 April 2016

Validate File Extension and Size Before Upload


image-file-formats.jpg
Here is the example to validate the file extension and size before upload. Regular expression has been used to validate the file extension. And to validate file size, we use size property of file input i.e., img.files[0].size. Onclick event of button, validate() function is being called. First, it checks for file extensions (jpg, jpeg, png, etc) and give error message for the files having other extensions. Then, it validates the file size by calculating the file size using img.files[0].size.
Example:
  1. <html>
  2. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  3. <script type="text/javascript">
  4. function Validate()
  5. {
  6.    var image =document.getElementById("image").value;
  7.    if(image!='')
  8.    {

Read full blog at our highly specific C, Java, PHP, Java, iPhone, Javascript Questions, about the topic described above "Validate File Extension and size Before Upload". You can also learn much more about different programming technologies and can enhance your tech skills.

Friday, 7 August 2015

Remove/add list using ng-click

Here is an simple example to add and delete list using angular ng-click

Html -

    <div ng-app="nameApp" ng-controller="TitleCtrl">
        <ul>
          <li ng-repeat="name in names">{{name}}
          <a href="" ng-click="removeName(name)">remove</a></li>
        </ul>
        <form ng-submit="addName()">
          <input type="text" ng-model="enteredName">
          <input type="submit" value="+">
        </form>
      </div>

For full blog about Remove/add list using ng-click visit Findnerd.

Also if you have any query related to javascript then you can post it on our javascript questions and answers developer forum. We are Happy to hear you!!!