Clearing the content of an input field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Clearing the content of an input field

    I get the following code to work in FireFox but not in IE v8

    Code:
    	document.getElementById('MyFile').value = ""
    When I examine it in the IE debugger, I can see that the code appears correct because when I put a watch on the statement it returns the current value.

    Why would this line then not clear out the content?
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    What kind of element is it? You may need to use innerHTML instead of value.

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      I tried innerHTML and that just created an error.

      the field was just an <input type="file" />

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Not sure, that original line works for me in both FF and IE8. Could you post the rest of your javascript?
        Are there javascript errors in IE?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Try using reset instead. If that's going to be a problem, you could put the field in its own form.

          There's a hack you could use where you replace the element with a new one either via DOM, or by refreshing the innerHTML (a proper hack).

          Comment

          Working...