I use this code in my ajax action file to clear form field after submit:
Code: Select all
<script>
parent.document.getElementById('field_id').value='';
</script>Any help would be extremely appreciated
Thanks in advance
Moderator: General Moderators
Code: Select all
<script>
parent.document.getElementById('field_id').value='';
</script>Code: Select all
<script>
parent.document.getElementById('field_id').value='';
</script>Code: Select all
<script>
field_id.setAttribute("value", "").
</script>Excellent point.ell0bo wrote:You can't force the value of a file input type, doing so would be a security issue.
Think of it this way, I create a page that has a hidden form. I keep rotating the value of that input field to look for files I might want to steal. I then auto submit the page to an iframe. I would be able to just steal files off of anyone's computer.
Code: Select all
<script>
function clearFileInput(elementId)
{
document.getElementById(elementId).innerHTML = document.getElementById(elementId).innerHTML;
}
</script>
<div id="fileInputContainer">
<input type="file" name="myFileUpload" />
</div>
<a href="#" onclick="clearFileInput('fileInputContainer');">Clear File Input</a>Code: Select all
<script>
function clearFileInput(elementId) {
document.getElementById(elementId).setAttribute('type', 'input');
document.getElementById(elementId).setAttribute('type', 'file');
}
</script>
<input type="file" name="myFileUpload" id="fileInput" />
<a href="#" onclick="clearFileInput('fileInput');">Clear File Input</a>