0

The following code works fine if I don't use return false; in imageload function. But if use return false; it's not working. I even tried break. It didn't help.

    function fileshow(sel){
       var file=sel.files[0];

        var imagetype=file.type;

        var match= ["image/jpeg","image/png","image/jpg"];
        if(!((imagetype==match[0]) || (imagetype==match[1]) || (imagetype==match[2]))){

          return false;
        }
        else{

            var reader = new FileReader();

          reader.onload = imageload;
          reader.readAsDataURL(sel.files[0]); 

        }
      }
    function imageload(e){
      $(".fileshow").each(function(){
        if($(this).val()==''){
          $(this).siblings(".inner_mainphoto").find("img").attr("src", e.target.result);
          return false;                 
        }
      });       
    }

Update

I want to break out of the each function if $(this).val() is empty.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77
  • 1
    You just forget to explain your expected behaviour. Posting non working code doesn't help to get what is your expected behaviour... – A. Wolff Mar 16 '16 at 13:54
  • A. Wolff bro I have updated my question – Sugumar Venkatesan Mar 16 '16 at 13:59
  • Possible duplicate of [How to break/exit from a each() function in JQuery?](http://stackoverflow.com/questions/1799284/how-to-break-exit-from-a-each-function-in-jquery) – Mark Schultheiss Mar 16 '16 at 14:03
  • @Mark Schultheiss bro this is not a duplicate question. there they told to use return false in the answer. I am already using return false but it is not working – Sugumar Venkatesan Mar 16 '16 at 14:05
  • What that says is you have not provided enough information OR that your `e.target.result` is the challenge. what does `console.dir(e);` before that conditional show for that value? – Mark Schultheiss Mar 16 '16 at 14:09
  • Is it even entering the `if` condition? – Akshay Mar 16 '16 at 14:35
  • @Akshay if I dont put return false there, it enters the if condition and changes the src attribute. but if I put return false the main function (imageload) itself not working – Sugumar Venkatesan Mar 17 '16 at 04:50

0 Answers0