[mdlug] jQuery help

Bob bob at starlinephoto.com
Mon Feb 29 12:39:12 EST 2016


I have a web form (wordpress plugin) with an image upload field. I need
to copy the file name to another field so I used this code:

<script type="text/javascript">
jQuery(document).ready(function($){
$('#field_g2gofx42').change(function(){
      var val1 = $("#field_g2gofx42").val();
      $("#field_jkn3x33").val(val1); }); });

This worked great when I tested from my Linux workstation and a Mac, I
get this:
P1010036.JPG

Of course, brain dead windose IE includes the whole local path and now I
get this:
C:\fakepath\P1010036.JPG

I tried modifying the code to strip out the "C:\fakepath\" but I either
get a blank field or Object object.

<script type="text/javascript">
jQuery(document).ready(function($){
val1 = $('#field_g2gofx42').val(function(i, v) { //index, current value
  return v.replace("C:\\fakepath\\", "");
        $("#field_jkn3x33").val(val1); }); });
</script>

I spent a good part of yesterday googleing this, found numerous
different ways to fix this but I'm lost as to how to incorporate them
into this script.

I'm not much of a JavaScript coder, I muddle along. Any help will be
greatly appreciated.

-- 
Bob Dion



More information about the mdlug mailing list