SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing the text from <input type='file'>

    I know I cannot insert text into an <input type='file'> (security reasons) but is there a way to clear the text with js? I have tried using the .value=""; but to no avail. Any feedback will be appreciated.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To elborate a bit more, I have the following field within my form:

    <form name="frm_grequest" id="frm_grequest" method="post" action="<?php echo $PHP_SELF; ?>">
    <?php
    echo "<input type='file' id='attachment_filename' name='attachment_filename' value='$_POST[attachment_filename]'>";
    ?>
    </form>

    This is just one element in a complex set of form fields that must be displayed or hidden via js depending on which radio buttons have been selected. As a result, I may need to clear the value of the <input type='file' id='attachment_filename'> again depending on which radio buttons have been selected.

    Here is the js I have tried:

    var attachment_filename = document.forms["frm_grequest"].elements["attachment_filename"];
    attachment_filename.value = "";

    Unfortunately, this does NOT clear the value of this field. Any suggestions?

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Location
    Italy
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that the only way to clear an input file field is to use the reset() method, however this will clear all the form fields! Thus, you should before retrieve the values of the other fields in the form, store them into variables, use the reset() method and then replace the values you want to preserve

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Davide Zanotti
    I think that the only way to clear an input file field is to use the reset() method, however this will clear all the form fields! Thus, you should before retrieve the values of the other fields in the form, store them into variables, use the reset() method and then replace the values you want to preserve
    Thanks for the feedback. I am still holding out hope that there is a way to clear the value w/o resetting the whole form.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •