I have a form that contains several browse fields for users to upload files.
There is also a hidden field that is populated using javascript.
This script reads the value of the browse field, splits the string and
returns the name of the file to the hidden field. This is done so the file
name can be re-used.
My problem is that the javascript appears to be unable to read the browse
field in order to send the file name to the hidden field. This works
perfectly in IE, but Mozilla, Netscape and Firebird is a different story.
Is there a problem with my code, or is this a browser problem? If it is a
code problem, do you have any suggestions?
Here is the code and how it works:
function get_image_name(browse_field, hidden_field) { //file_name
var local_image = document.getElementById(browse_field).value;
var file_path_array = local_image.split("\\");
document.getElementById(hidden_field).value =
file_path_array[file_path_array.length-1];
}
Each browser and hidden form field have the same name, except for a number.
The values passed tot he function could be read as ('image_2',
'image_name_2')
1) browse_field - An onChange event triggers this function and the value of
the browse_field is stored in the variable local image.
2) The value of local_image is then split to create an array of the
directories and file name. I only need the file name.
3) The value of the last element in the array (the file name) is then passed
to the hidden field
Thanks for any and all help I can get.
Cy