ARTLoe ARTLoe - 1 year ago 76
jQuery Question

converting from Javascript to JQuery - Rails 4

Could one kindly advise me how i would write the below javascript in jQuery? i am unsure as my converted code is not working


document.getElementById("userj_cvattachment").onchange = function () {
document.getElementById("uploadFile").value = this.value;

Answer Source

Lets break it down.

  1. You select an element by: document.getElementById("userj_cvattachment")

  2. You attach a handler to its change event: .onchange = function (){ }

    $("#userj_cvattachment").on("change", function(){ });
  3. You select another element by id

  4. You change its value: .value = this.value;

    $("#userj_cvattachment").on("change", function(){