Reading Browser Field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cy

    Reading Browser Field

    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.getEle mentById(browse _field).value;
    var file_path_array = local_image.spl it("\\");
    document.getEle mentById(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


  • Jeff Thies

    #2
    Re: Reading Browser Field

    > This script reads the value of the browse field, splits the string and[color=blue]
    > 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://file_name[/color]

    What's with the file:???
    [color=blue]
    > var local_image = document.getEle mentById(browse _field).value;
    > var file_path_array = local_image.spl it("\\");[/color]

    I would be very suspicious of the above line as you don't know how the
    browser is reading the file path.

    Why don't you put in some alerts so you can trace the variables?

    alert(local_ima ge);
    alert(file_path _array[file_path_array .length-1);

    Jeff.

    [color=blue]
    > document.getEle mentById(hidden _field).value =
    > file_path_array[file_path_array .length-1];
    > }
    >
    > Each browser and hidden form field have the same name, except for a[/color]
    number.[color=blue]
    > 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[/color]
    of[color=blue]
    > 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[/color]
    passed[color=blue]
    > to the hidden field
    >
    > Thanks for any and all help I can get.
    > Cy
    >
    >[/color]


    Comment

    Working...