javascript - Change handler not working -


i new jquery , having trouble getting simple html page containing jquery (that gleaned stack overflow thread, unfortunately wasn't complete enough jquery newbie me, apparently!) work properly. when choose filename, expect "mytext" text input field contain name of file uploaded, not happen.

$(document).ready(function() {    $('#myfile').bind('change', function() {      var filename = '';      filename = $(this).val();      $('#mytext').html(filename);    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <form>    <input type="text" id="mytext" name="mytext">    <input type="file" id="myfile" name="myfile">  </form>

  1. you missing /script on jquery tag
  2. you using .html() instead of .val() field
  3. you should use .on instead of .bind

$('#myfile').on('change', function() {          filename = $(this).val().split('\\').pop();          $('#mytext').val(filename);     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" id="mytext" name="mytext">  <input type="file" id="myfile" name="myfile">


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -