Reset a File Input

Discussion in 'Javascript' started by YoBro, Sep 7, 2004.

  1. YoBro

    YoBro Guest

    Hi,

    Is this possible, if so how would you go about it.

    I have a reasonably large form that includes 6 file input fields.
    I wanted to create an option to allow the user to reset only the file input
    fields. Currently if they select an image to upload and realise it is the
    wrong one there is no way of resetting it. Except of course, manually
    deleting the text out of the field.

    Because you cannot reference and change the value of a file input, I cannot
    set the value to "".

    Is there any other way to add a rest button but specify the fields that you
    want to reset. I do not want to rest the entire form.

    Many thanks.

    YoBro
    YoBro, Sep 7, 2004
    #1
    1. Advertising

  2. YoBro

    Joakim Braun Guest

    "YoBro" <> skrev i meddelandet
    news:nIp%c.23022$...
    > Hi,
    >
    > Is this possible, if so how would you go about it.
    >
    > I have a reasonably large form that includes 6 file input fields.
    > I wanted to create an option to allow the user to reset only the file

    input
    > fields. Currently if they select an image to upload and realise it is the
    > wrong one there is no way of resetting it. Except of course, manually
    > deleting the text out of the field.
    >
    > Because you cannot reference and change the value of a file input, I

    cannot
    > set the value to "".
    >
    > Is there any other way to add a rest button but specify the fields that

    you
    > want to reset. I do not want to rest the entire form.
    >
    > Many thanks.
    >
    > YoBro


    I hope someone has a brighter idea than this: Save all form element values
    except the file inputs, reset the form, then set all form element values
    except the file inputs back to the corresponding saved values.

    Joakim Braun
    Joakim Braun, Sep 7, 2004
    #2
    1. Advertising

  3. YoBro

    PDannyD Guest

    "YoBro" <> wrote in message
    news:nIp%c.23022$
    > Hi,
    >
    > Is this possible, if so how would you go about it.
    >
    > I have a reasonably large form that includes 6 file input fields.
    > I wanted to create an option to allow the user to reset only the file
    > input fields. Currently if they select an image to upload and realise
    > it is the wrong one there is no way of resetting it. Except of
    > course, manually deleting the text out of the field.
    >
    > Because you cannot reference and change the value of a file input, I
    > cannot set the value to "".
    >
    > Is there any other way to add a rest button but specify the fields
    > that you want to reset. I do not want to rest the entire form.


    Use two forms?
    PDannyD, Sep 7, 2004
    #3
  4. YoBro

    Ian Sedwell Guest

    On 2004/09/07 22:57, in article chlat1$eak$, "PDannyD"
    <> wrote:

    > "YoBro" <> wrote in message
    > news:nIp%c.23022$
    >> Hi,
    >>
    >> Is this possible, if so how would you go about it.
    >>
    >> I have a reasonably large form that includes 6 file input fields.
    >> I wanted to create an option to allow the user to reset only the file
    >> input fields. Currently if they select an image to upload and realise
    >> it is the wrong one there is no way of resetting it. Except of
    >> course, manually deleting the text out of the field.
    >>
    >> Because you cannot reference and change the value of a file input, I
    >> cannot set the value to "".
    >>
    >> Is there any other way to add a rest button but specify the fields
    >> that you want to reset. I do not want to rest the entire form.

    >
    > Use two forms?
    >
    >



    I didn't know you couldn't mess with the value of a file input field. Never
    had to try! But it makes sense that that is so from a security point of
    view. Ah well, live and learn, eh.

    I think what I'd do, is save the field values I wanted to keep into cookies
    or global variables, reset the form and then restore the retained values to
    their original fields from their temporary containers.

    Maybe there's a more elegant way.

    Cheers

    Ian
    Ian Sedwell, Sep 7, 2004
    #4
  5. YoBro

    YoBro Guest

    Hmmm,

    It is a really complicated form already, and massive, but quite a bit of
    DHTML for different aspects of it. It is used specifically in Internet
    Explorer, and is part of a companies Intranet. So I don't need anything
    cross browser compatible, but I was hoping for an easy fix.

    I thought about the cookie, idea but it is alot of work. I might have to
    head down that road. It is a shame the reset button cannot have specified
    values. This way you could click reset and specify which fields you want to
    reset.

    Thanks for the feedback!

    "Ian Sedwell" <> wrote in message
    news:BD63F4C5.CF1B%...
    > On 2004/09/07 22:57, in article chlat1$eak$,
    > "PDannyD"
    > <> wrote:
    >
    >> "YoBro" <> wrote in message
    >> news:nIp%c.23022$
    >>> Hi,
    >>>
    >>> Is this possible, if so how would you go about it.
    >>>
    >>> I have a reasonably large form that includes 6 file input fields.
    >>> I wanted to create an option to allow the user to reset only the file
    >>> input fields. Currently if they select an image to upload and realise
    >>> it is the wrong one there is no way of resetting it. Except of
    >>> course, manually deleting the text out of the field.
    >>>
    >>> Because you cannot reference and change the value of a file input, I
    >>> cannot set the value to "".
    >>>
    >>> Is there any other way to add a rest button but specify the fields
    >>> that you want to reset. I do not want to rest the entire form.

    >>
    >> Use two forms?
    >>
    >>

    >
    >
    > I didn't know you couldn't mess with the value of a file input field.
    > Never
    > had to try! But it makes sense that that is so from a security point of
    > view. Ah well, live and learn, eh.
    >
    > I think what I'd do, is save the field values I wanted to keep into
    > cookies
    > or global variables, reset the form and then restore the retained values
    > to
    > their original fields from their temporary containers.
    >
    > Maybe there's a more elegant way.
    >
    > Cheers
    >
    > Ian
    >
    YoBro, Sep 8, 2004
    #5
  6. YoBro

    J. J. Cale Guest

    "YoBro" <> wrote in message
    news:nIp%c.23022$...
    > Hi,
    >
    > Is this possible, if so how would you go about it.
    >
    > I have a reasonably large form that includes 6 file input fields.
    > I wanted to create an option to allow the user to reset only the file

    input
    > fields. Currently if they select an image to upload and realise it is the
    > wrong one there is no way of resetting it. Except of course, manually
    > deleting the text out of the field.
    >
    > Because you cannot reference and change the value of a file input, I

    cannot
    > set the value to "".
    >

    document.forms['yourFormName'].yourFileInputName.value="";
    > Is there any other way to add a rest button but specify the fields that

    you
    > want to reset. I do not want to rest the entire form.
    >

    <form name='yourFormName' onsubmit='yourFunction()>
    <input type="file" name="yourFileInputName">
    </form>
    <script type=text/javascript>
    function yourFunction() {
    // validate what you want here;
    // change form field value as necessary (see above comment)
    if(!confirm("Ok to submit or whatever") return;
    }
    </script>
    Jimbo
    > Many thanks.
    >
    > YoBro
    >
    >
    J. J. Cale, Sep 8, 2004
    #6
  7. YoBro

    G Roydor Guest

    YoBro a écrit:
    > Hi,
    >
    > Is this possible, if so how would you go about it.
    >
    > I have a reasonably large form that includes 6 file input fields.
    > I wanted to create an option to allow the user to reset only the file input
    > fields. Currently if they select an image to upload and realise it is the
    > wrong one there is no way of resetting it. Except of course, manually
    > deleting the text out of the field.


    essayez avec 6 forms plus une qui récapitule
    et soumettez par la methode submit après avoir collationné les fichiers
    valides

    test with 6 forms more one which recapitulates and submit by the method
    ..submit() after having collated the valid files

    GR

    >
    > Because you cannot reference and change the value of a file input, I cannot
    > set the value to "".
    >
    > Is there any other way to add a rest button but specify the fields that you
    > want to reset. I do not want to rest the entire form.
    >
    > Many thanks.
    >
    > YoBro
    >
    >
    G Roydor, Sep 8, 2004
    #7
  8. YoBro

    Philip Ronan Guest

    On 8/9/04 1:58 am, YoBro wrote:

    > Hmmm,
    >
    > It is a really complicated form already, and massive, but quite a bit of
    > DHTML for different aspects of it. It is used specifically in Internet
    > Explorer, and is part of a companies Intranet. So I don't need anything
    > cross browser compatible, but I was hoping for an easy fix.


    Associate each file input field with a checkbox that toggles the field's
    'disabled' flag. (Disabled fields are always unsuccessful, so their contents
    should be ignored.)

    --
    Philip Ronan

    (Please remove the "z"s if replying by email)
    Philip Ronan, Sep 8, 2004
    #8
  9. YoBro

    YoBro Guest

    Hi,

    You cannot change a file input field with JavaScript (for security reasons).
    So this method won't work.

    YoBro


    "J. J. Cale" <> wrote in message
    news:413e9cb9$1@news.012.net.il...
    >
    > "YoBro" <> wrote in message
    > news:nIp%c.23022$...
    >> Hi,
    >>
    >> Is this possible, if so how would you go about it.
    >>
    >> I have a reasonably large form that includes 6 file input fields.
    >> I wanted to create an option to allow the user to reset only the file

    > input
    >> fields. Currently if they select an image to upload and realise it is the
    >> wrong one there is no way of resetting it. Except of course, manually
    >> deleting the text out of the field.
    >>
    >> Because you cannot reference and change the value of a file input, I

    > cannot
    >> set the value to "".
    >>

    > document.forms['yourFormName'].yourFileInputName.value="";
    >> Is there any other way to add a rest button but specify the fields that

    > you
    >> want to reset. I do not want to rest the entire form.
    >>

    > <form name='yourFormName' onsubmit='yourFunction()>
    > <input type="file" name="yourFileInputName">
    > </form>
    > <script type=text/javascript>
    > function yourFunction() {
    > // validate what you want here;
    > // change form field value as necessary (see above comment)
    > if(!confirm("Ok to submit or whatever") return;
    > }
    > </script>
    > Jimbo
    >> Many thanks.
    >>
    >> YoBro
    >>
    >>

    >
    >
    YoBro, Sep 8, 2004
    #9
  10. YoBro

    YoBro Guest

    Hi,

    This was going to be my option, and have sort of implemented it, if they
    re-use an image already on the server. It disables the file input so they
    cannot upload an image as well as re-use an image.

    YoBro

    "Philip Ronan" <> wrote in message
    news:BD649160.20CC8%...
    > On 8/9/04 1:58 am, YoBro wrote:
    >
    >> Hmmm,
    >>
    >> It is a really complicated form already, and massive, but quite a bit of
    >> DHTML for different aspects of it. It is used specifically in Internet
    >> Explorer, and is part of a companies Intranet. So I don't need anything
    >> cross browser compatible, but I was hoping for an easy fix.

    >
    > Associate each file input field with a checkbox that toggles the field's
    > 'disabled' flag. (Disabled fields are always unsuccessful, so their
    > contents
    > should be ignored.)
    >
    > --
    > Philip Ronan
    >
    > (Please remove the "z"s if replying by email)
    >
    >
    YoBro, Sep 8, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PW

    INPUT IMAGE - RESET ?

    PW, Sep 3, 2004, in forum: HTML
    Replies:
    28
    Views:
    8,035
  2. Guest

    reset input screen

    Guest, Jun 20, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    98
    Mythran
    Jun 20, 2005
  3. jparlato
    Replies:
    3
    Views:
    265
    jparlato
    May 26, 2006
  4. apstein

    Form input fields reset problem

    apstein, Dec 1, 2007, in forum: Javascript
    Replies:
    2
    Views:
    149
    andrew
    Dec 3, 2007
  5. andrew

    Form input fields reset problem

    andrew, Dec 1, 2007, in forum: Javascript
    Replies:
    0
    Views:
    80
    andrew
    Dec 1, 2007
Loading...

Share This Page