-1

I have got this HTML code

<img src="../img/1.jpg" class="img">
<img src="../img/2.jpg" class="img">
<img src="../img/3.jpg" class="img">
<img src="../img/4.jpg" class="img">
<input type="file" name="file" id="file" onchange="bgchange(this)" >

And this jquery

$(".img").click(function(){
                        var srcat=$(this).attr('src');
                        $("#file").attr('value',srcat);
                        alert($("#file").val());
                });

But it is not changing any value it stays empty.Is there anyway i can change that?

Murad
  • 167
  • 1
  • 2
  • 13

1 Answers1

4

You are not allowed to change the value of input[type="file'] via script. This is a security mechanism. If this was possible, websites could steal any file in your hard drive. Not very cool.

Jonas Meinerz
  • 612
  • 3
  • 9