Why javascript IF only works one time?

Posted by Emily on Stack Overflow See other posts from Stack Overflow or by Emily
Published on 2010-04-08T18:21:59Z Indexed on 2010/04/08 18:23 UTC
Read the original article Hit count: 336

I have javascript code which copy the value of input file and past it in the text box in real time.

<script>
function copyit(){

var thephoto=document.getElementById('thephoto').value;
var fileonchange=document.getElementById('fileonchange').value;

if(!thephoto==fileonchange){
document.getElementById('fileonchange').value=thephoto;
}

}

window.setInterval("copyit()", 500);  
</script>

Choose File : <input type="file" id="thephoto"><br>
Here Is the file name : <input type="text" id="fileonchange">

Sadly this only works one time and then stops pasting the value when changing the file again. ( i mean you should reload the page to works again)

Is IF has a cache or something? you can try the code by yourself to see.

Thank you all

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events