Link to home
Start Free TrialLog in
Avatar of rick123456789
rick123456789

asked on

Copy field to another field web form

I am trying to build on online employment application.  I've got everything set but one item.  Part of the application process is they can upload a resume if they would like, the file field browses the file system so they can select a file.  Once selected it uploads with the form information they have provided.  I am trying to copy one field to another field within the form so when the data is saved, I know the name of the file they uploaded for their resume.  Everything works fine on explorer, google chrome, mozilla.  I can't get this to work on Safari, Macs or any mobile device.  Here is the code I am using to copy the original file field name to another hidden text field.    

<script>  
    var form = document.getElementById('form1');
form.elements.fle.onblur = function () {
    var form = this.form;
    form.elements.fle2.value = form.elements.fle.value;
};
    </script>

The file transfer and all other data are saved on every type of browser (including the mobile devices) the only thing not working is the name of the file they uploaded on the systems I mentioned before (to the hidden text field).  I hope I have provided enough information.  I am somewhat new at this web development thing and hoping someone can point me in the right direction.

Thank you in advance for any assistance.
Avatar of dgrafx
dgrafx
Flag of United States of America image

function blr(f1,f2) {
     document.getElementById(f2).value = document.getElementById(f1).value;
}
should work across browsers
you can use onblur="blr('fle1','fle2')"
you need to give each input an id - which i'm not sure if you've done or not
input id="fle1" & input id="fle2"
greetings  rick123456789, , I am not sure that your Form element access with code -
     form.elements.fle2.value = form.elements.fle.value;

is at all correct for some browsers. For me if I know the "name" of a form element, I can just property it from the DOM FORM object, as in if names is "hidden1" and "text1"
form1.hidden1.value = form1.text1.value;

if you use the FORM elements array, you can get individual elements by NAME with -
   form1.elements.namedItem("hidden1").value;

However the FORM file upload INPUT is a Different setup than any other Input, and it's "File name" value is NOT available in some browsers for access by some javascripts.
But, On the SERVER side code you already get the UPLOADED file name, without any hidden input copy, as all file uploads are delivered with a "File Name" from the Operating System that they came from.
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rick123456789
rick123456789

ASKER

Slick812,

php writes the information on server side to a text file that is downloaded and imported into a database at the main office.  Download and import is automated.
sorry previous post should have been addressed to "dgrafx"
Got it.  Thanks dgrafx.  I had to dump the java and go back server side with php.  Once I got it to write the file name via the php post all browsers work.
Thanks again :-)
Glad it worked out!