clearing a file input field

Results 1 to 2 of 2

Thread: clearing a file input field

  1. #1
    Join Date
    Dec 1969

    Default clearing a file input field

    All I want to do is validate the file extension of the file picked by a user. So on change I check the type and clear the field value if it&#039;s the wrong type; right? Well everything works except it does not clear the field. Is there a trick to clearing the field of a file input type?<BR><BR>Here&#039;s the function...<BR>===============================<BR> function checkFileExt(fld){<BR>if (fld.value.substring(fld.value.length-3,fld.value.length) =="gif" &#124&#124 fld.value.substring(fld.value.length-3,fld.value.length)=="jpg" &#124&#124 fld.value.substring(fld.value.length-3,fld.value.length)=="jpeg") {<BR>}else{<BR>alert("Only gif, jpg or jpeg files are permitted!");<BR>fld.value="";<BR>}<BR>} <BR>==========================================<BR> Here&#039;s the HTML field...<BR>====================================== ====<BR>&#060;INPUT id="filToUpload" name="filToUpload" onchange="checkFileExt(this)" type="file" runat="server"&#062;<BR>========================== ================<BR><BR>Thanks in advance for your help.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: clearing a file input field

    As a security precaution, file inputs are read-only. you can&#039;t write to them, even a blank value.

Posting Permissions

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