Bootstrap Twitter input type file how to clear the file?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm implementing option for the user in the form where they can select one of allowed files and upload. This feature interface is build in Bootstrap 3 and I found one of the blogs that helped me style the interface. However, I'm wondering if there is a good option to clear/remove selected file? In case if user decided not to upload the file how they can remove it? I would need like X delete button on the very right side. Also file has to be remove with JavaScript I guess. If anyone knows the way to achieve this please let me know. Here is my code example:






$("#frm_file").on("change", uploadFile);
function uploadFile()
var ftype = $(this).get(0).files[0].type,
fname = $(this).get(0).files[0].name,
fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
console.log(fname);
$("#frm_filename").val(fname);

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="form-group">
<label class="control-label" for="file"><span class="label label-default">File:</span></label>
<div class="input-group">
<label class="input-group-btn">
<span class="btn btn-primary">
Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
</span>
</label>
<input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
</div>
</div>












share|improve this question




























    0















    I'm implementing option for the user in the form where they can select one of allowed files and upload. This feature interface is build in Bootstrap 3 and I found one of the blogs that helped me style the interface. However, I'm wondering if there is a good option to clear/remove selected file? In case if user decided not to upload the file how they can remove it? I would need like X delete button on the very right side. Also file has to be remove with JavaScript I guess. If anyone knows the way to achieve this please let me know. Here is my code example:






    $("#frm_file").on("change", uploadFile);
    function uploadFile()
    var ftype = $(this).get(0).files[0].type,
    fname = $(this).get(0).files[0].name,
    fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
    validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
    console.log(fname);
    $("#frm_filename").val(fname);

    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <div class="form-group">
    <label class="control-label" for="file"><span class="label label-default">File:</span></label>
    <div class="input-group">
    <label class="input-group-btn">
    <span class="btn btn-primary">
    Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
    </span>
    </label>
    <input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
    </div>
    </div>












    share|improve this question
























      0












      0








      0








      I'm implementing option for the user in the form where they can select one of allowed files and upload. This feature interface is build in Bootstrap 3 and I found one of the blogs that helped me style the interface. However, I'm wondering if there is a good option to clear/remove selected file? In case if user decided not to upload the file how they can remove it? I would need like X delete button on the very right side. Also file has to be remove with JavaScript I guess. If anyone knows the way to achieve this please let me know. Here is my code example:






      $("#frm_file").on("change", uploadFile);
      function uploadFile()
      var ftype = $(this).get(0).files[0].type,
      fname = $(this).get(0).files[0].name,
      fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
      validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
      console.log(fname);
      $("#frm_filename").val(fname);

      <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <div class="form-group">
      <label class="control-label" for="file"><span class="label label-default">File:</span></label>
      <div class="input-group">
      <label class="input-group-btn">
      <span class="btn btn-primary">
      Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
      </span>
      </label>
      <input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
      </div>
      </div>












      share|improve this question














      I'm implementing option for the user in the form where they can select one of allowed files and upload. This feature interface is build in Bootstrap 3 and I found one of the blogs that helped me style the interface. However, I'm wondering if there is a good option to clear/remove selected file? In case if user decided not to upload the file how they can remove it? I would need like X delete button on the very right side. Also file has to be remove with JavaScript I guess. If anyone knows the way to achieve this please let me know. Here is my code example:






      $("#frm_file").on("change", uploadFile);
      function uploadFile()
      var ftype = $(this).get(0).files[0].type,
      fname = $(this).get(0).files[0].name,
      fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
      validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
      console.log(fname);
      $("#frm_filename").val(fname);

      <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <div class="form-group">
      <label class="control-label" for="file"><span class="label label-default">File:</span></label>
      <div class="input-group">
      <label class="input-group-btn">
      <span class="btn btn-primary">
      Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
      </span>
      </label>
      <input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
      </div>
      </div>








      $("#frm_file").on("change", uploadFile);
      function uploadFile()
      var ftype = $(this).get(0).files[0].type,
      fname = $(this).get(0).files[0].name,
      fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
      validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
      console.log(fname);
      $("#frm_filename").val(fname);

      <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <div class="form-group">
      <label class="control-label" for="file"><span class="label label-default">File:</span></label>
      <div class="input-group">
      <label class="input-group-btn">
      <span class="btn btn-primary">
      Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
      </span>
      </label>
      <input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
      </div>
      </div>





      $("#frm_file").on("change", uploadFile);
      function uploadFile()
      var ftype = $(this).get(0).files[0].type,
      fname = $(this).get(0).files[0].name,
      fextension = fname.split('.').pop(), // Another way to get file extension: fname.substring(fname.lastIndexOf('.')+1);
      validExtensions = ["jpg","jpeg","png","gif","doc","docx","xls","xlsx","txt","pdf"];
      console.log(fname);
      $("#frm_filename").val(fname);

      <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script language="javascript" type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <div class="form-group">
      <label class="control-label" for="file"><span class="label label-default">File:</span></label>
      <div class="input-group">
      <label class="input-group-btn">
      <span class="btn btn-primary">
      Browse&hellip; <input type="file" name="frm_file" id="frm_file" style="display: none;">
      </span>
      </label>
      <input type="text" class="form-control" name="frm_filename" id="frm_filename" readonly>
      </div>
      </div>






      javascript jquery twitter-bootstrap twitter-bootstrap-3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 15:03









      espresso_coffeeespresso_coffee

      2,11552150




      2,11552150






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Here is a very basic example using the bootstrap button on the right hand side. This is practically taken from the bootstrap 3.7 website. https://getbootstrap.com/docs/3.3/css/#forms





           <input type="text" class="form-control" id="inputGroupSuccess2" aria-describedby="inputGroupSuccess2Status">
          </div>
          <span id="clear" class="input-group-addon">X</span>
          </div>

          <script>
          Document.getElementById("clear").addEventListener("click", clearInput);

          Function clearInput()
          Document.getElementById("clear").Value = "";

          </script>





          share|improve this answer






























            1














            Try something like



            document.getElementById('frm_file').value = "";


            If not, try this answer.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322299%2fbootstrap-twitter-input-type-file-how-to-clear-the-file%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Here is a very basic example using the bootstrap button on the right hand side. This is practically taken from the bootstrap 3.7 website. https://getbootstrap.com/docs/3.3/css/#forms





               <input type="text" class="form-control" id="inputGroupSuccess2" aria-describedby="inputGroupSuccess2Status">
              </div>
              <span id="clear" class="input-group-addon">X</span>
              </div>

              <script>
              Document.getElementById("clear").addEventListener("click", clearInput);

              Function clearInput()
              Document.getElementById("clear").Value = "";

              </script>





              share|improve this answer



























                1














                Here is a very basic example using the bootstrap button on the right hand side. This is practically taken from the bootstrap 3.7 website. https://getbootstrap.com/docs/3.3/css/#forms





                 <input type="text" class="form-control" id="inputGroupSuccess2" aria-describedby="inputGroupSuccess2Status">
                </div>
                <span id="clear" class="input-group-addon">X</span>
                </div>

                <script>
                Document.getElementById("clear").addEventListener("click", clearInput);

                Function clearInput()
                Document.getElementById("clear").Value = "";

                </script>





                share|improve this answer

























                  1












                  1








                  1







                  Here is a very basic example using the bootstrap button on the right hand side. This is practically taken from the bootstrap 3.7 website. https://getbootstrap.com/docs/3.3/css/#forms





                   <input type="text" class="form-control" id="inputGroupSuccess2" aria-describedby="inputGroupSuccess2Status">
                  </div>
                  <span id="clear" class="input-group-addon">X</span>
                  </div>

                  <script>
                  Document.getElementById("clear").addEventListener("click", clearInput);

                  Function clearInput()
                  Document.getElementById("clear").Value = "";

                  </script>





                  share|improve this answer













                  Here is a very basic example using the bootstrap button on the right hand side. This is practically taken from the bootstrap 3.7 website. https://getbootstrap.com/docs/3.3/css/#forms





                   <input type="text" class="form-control" id="inputGroupSuccess2" aria-describedby="inputGroupSuccess2Status">
                  </div>
                  <span id="clear" class="input-group-addon">X</span>
                  </div>

                  <script>
                  Document.getElementById("clear").addEventListener("click", clearInput);

                  Function clearInput()
                  Document.getElementById("clear").Value = "";

                  </script>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 15:15









                  Sean LeroySean Leroy

                  687




                  687























                      1














                      Try something like



                      document.getElementById('frm_file').value = "";


                      If not, try this answer.






                      share|improve this answer



























                        1














                        Try something like



                        document.getElementById('frm_file').value = "";


                        If not, try this answer.






                        share|improve this answer

























                          1












                          1








                          1







                          Try something like



                          document.getElementById('frm_file').value = "";


                          If not, try this answer.






                          share|improve this answer













                          Try something like



                          document.getElementById('frm_file').value = "";


                          If not, try this answer.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 15:06









                          elkenelken

                          138110




                          138110



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322299%2fbootstrap-twitter-input-type-file-how-to-clear-the-file%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kleinkühnau

                              Makov (Slowakei)

                              Deutsches Schauspielhaus