[mdlug] jQuery help

Bob bob at starlinephoto.com
Fri Mar 4 09:47:31 EST 2016


That for the help, I thought I had another fix without using the jQuery
code put that ended up not working. Will give this a try and see what
happens.

Thanks

Bob

On 02/29/2016 04:49 PM, Mark Thuemmel wrote:
> On 02/29/2016 12:39 PM, Bob wrote:
>> 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.
>>
>
> I'm not a javascripter either, but I'd guess basename is what you want
>
>
> function basename(str, sep) {
>     return str.substr(str.lastIndexOf(sep) + 1);
> }
>
>
> call it like this
>
> basename('file.txt','\');
>
>
>
> or maybe this:
>
> function basename(path) {
>     return path.replace(/\\/g,'/').replace( /.*\//, '' );
> }
>
>
>
> _______________________________________________
> mdlug mailing list
> mdlug at mdlug.org
> http://mdlug.org/mailman/listinfo/mdlug



More information about the mdlug mailing list