简体   繁体   中英

How to get value of file upload by field name, not id?

I am using a plugin with Wordpress for contact forms, and have a file upload. I can't assign an "ID" or class to the field, it only has a name. How can I select this field to get the value and display it in a text field? I was using this code, which worked perfectly when the upload field had an ID.. So I need to figure out how to modify it to work with just a field name.. The name is "CustomFormsFileUpload_945"

$(function() {
    $("#ufo-field-id-945").change(function() {
        $("#ufo-field-id-948").val($(this).val())

        var string = $("#ufo-field-id-948").val();
        var new_string = string.replace('C:\\fakepath\\', '');
        $("#ufo-field-id-948").val(new_string);

    });
});​

You can use an attribute selector:

$('[name="CustomFormsFileUpload_945"]')

(And if you don't actually have both 945 and 948 there, you should keep it in a variable.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM