How can I copy the value from the form file upload field to another form text field?

I have one page with two different forms. The first form allows the user to upload and email an image file, the second form creates a URL based on user input.

To add the image name to the url, I need to have a field on the second form that copies the image name from the field on the first form (I would rather not have the user view and select the image twice on the same page). The best way I've found to copy data from one field to another across forms is with jQuery code: http://jsfiddle.net/nA37d/ , but it doesn't work for my purposes. For example, it works fine from text box to text box, but it doesn't work from file box to text box, or file box to file box.

Is there a way to grab the value of a file field in form 1 and copy it to any field in form 2? Here is my main code:

<script type="text/javascript">
$(function(){
    bindGroups();
});

var bindGroups = function() {
    // First copy values
    $("input[name='logotoo']").val($("input[name='logoname']").val());

    // Then bind fields
    $("input[name='logoname']").keyup(function() {
        $("input[name='logotoo']").val($(this).val());
    });
};
</script>


<form action="#..." method="post" enctype="multipart/form-data">
<input type="file" name="logoname" value="1" />
<input type="submit" value="Upload" /></form>


<form name="form2" action="/url/" method="get">
<label>Logo Name</label> <input type="text" name="logotoo" />
<input type="submit" value="Generate URL" /></form>

      

Thanks for any help you can give!

+3


source to share


1 answer


Just use the handler change()

for the input type file, not the keyboard:

http://jsfiddle.net/nA37d/169/

 $("input[name='a1']").change(function() {
        $("input[name='b1']").val($(this).val());
    });

      



For a file input to file input, I don't think it is possible for security reasons.

By the way, this code needs to be refactored.

+2


source







All Articles