Reset a File Input

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

    Reset a File Input

    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


  • Joakim Braun

    #2
    Re: Reset a File Input

    "YoBro" <yobro@wazzup.c o.nz> skrev i meddelandet
    news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz. ..[color=blue]
    > 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[/color]
    input[color=blue]
    > 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[/color]
    cannot[color=blue]
    > set the value to "".
    >
    > Is there any other way to add a rest button but specify the fields that[/color]
    you[color=blue]
    > want to reset. I do not want to rest the entire form.
    >
    > Many thanks.
    >
    > YoBro[/color]

    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


    Comment

    • PDannyD

      #3
      Re: Reset a File Input

      "YoBro" <yobro@wazzup.c o.nz> wrote in message
      news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz[color=blue]
      > 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.[/color]

      Use two forms?


      Comment

      • Ian Sedwell

        #4
        Re: Reset a File Input

        On 2004/09/07 22:57, in article chlat1$eak$1@ne ws6.svr.pol.co. uk, "PDannyD"
        <dan1970@REMOVE THISBITscenicpl ace.freeserve.c o.uk> wrote:
        [color=blue]
        > "YoBro" <yobro@wazzup.c o.nz> wrote in message
        > news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz[color=green]
        >> 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.[/color]
        >
        > Use two forms?
        >
        >[/color]


        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

        Comment

        • YoBro

          #5
          Re: Reset a File Input

          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" <ian.sedwell@bt click.com> wrote in message
          news:BD63F4C5.C F1B%ian.sedwell @btclick.com...[color=blue]
          > On 2004/09/07 22:57, in article chlat1$eak$1@ne ws6.svr.pol.co. uk,
          > "PDannyD"
          > <dan1970@REMOVE THISBITscenicpl ace.freeserve.c o.uk> wrote:
          >[color=green]
          >> "YoBro" <yobro@wazzup.c o.nz> wrote in message
          >> news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz[color=darkred]
          >>> 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.[/color]
          >>
          >> Use two forms?
          >>
          >>[/color]
          >
          >
          > 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
          >[/color]


          Comment

          • J. J. Cale

            #6
            Re: Reset a File Input


            "YoBro" <yobro@wazzup.c o.nz> wrote in message
            news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz. ..[color=blue]
            > 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[/color]
            input[color=blue]
            > 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[/color]
            cannot[color=blue]
            > set the value to "".
            >[/color]
            document.forms['yourFormName'].yourFileInputN ame.value="";[color=blue]
            > Is there any other way to add a rest button but specify the fields that[/color]
            you[color=blue]
            > want to reset. I do not want to rest the entire form.
            >[/color]
            <form name='yourFormN ame' onsubmit='yourF unction()>
            <input type="file" name="yourFileI nputName">
            </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[color=blue]
            > Many thanks.
            >
            > YoBro
            >
            >[/color]


            Comment

            • G Roydor

              #7
              Re: Reset a File Input


              YoBro a écrit:[color=blue]
              > 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.[/color]

              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
              [color=blue]
              >
              > 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
              >
              >[/color]

              Comment

              • Philip Ronan

                #8
                Re: Reset a File Input

                On 8/9/04 1:58 am, YoBro wrote:
                [color=blue]
                > 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.[/color]

                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
                phil.ronanzzz@v irgin.net
                (Please remove the "z"s if replying by email)


                Comment

                • YoBro

                  #9
                  Re: Reset a File Input

                  Hi,

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

                  YoBro


                  "J. J. Cale" <photom@netvisi on.net.il> wrote in message
                  news:413e9cb9$1 @news.012.net.i l...[color=blue]
                  >
                  > "YoBro" <yobro@wazzup.c o.nz> wrote in message
                  > news:nIp%c.2302 2$N77.1053430@n ews.xtra.co.nz. ..[color=green]
                  >> 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[/color]
                  > input[color=green]
                  >> 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[/color]
                  > cannot[color=green]
                  >> set the value to "".
                  >>[/color]
                  > document.forms['yourFormName'].yourFileInputN ame.value="";[color=green]
                  >> Is there any other way to add a rest button but specify the fields that[/color]
                  > you[color=green]
                  >> want to reset. I do not want to rest the entire form.
                  >>[/color]
                  > <form name='yourFormN ame' onsubmit='yourF unction()>
                  > <input type="file" name="yourFileI nputName">
                  > </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[color=green]
                  >> Many thanks.
                  >>
                  >> YoBro
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • YoBro

                    #10
                    Re: Reset a File Input

                    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" <phil.ronanzzz@ virgin.net> wrote in message
                    news:BD649160.2 0CC8%phil.ronan zzz@virgin.net. ..[color=blue]
                    > On 8/9/04 1:58 am, YoBro wrote:
                    >[color=green]
                    >> 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.[/color]
                    >
                    > 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
                    > phil.ronanzzz@v irgin.net
                    > (Please remove the "z"s if replying by email)
                    >
                    >[/color]


                    Comment

                    Working...