/    Sign up×
Community /Pin to ProfileBookmark

File Input Clear Or Reset Help Needed

I am trying to pull a value from a file input form and now all i want to do is reset or clear the value before the page gets submitted and the file input value is posted.

does anyone know how to do this??? ? ?

<html>
<head>
<script type=”text/javascript”>

function submitform()
{
var empty = “”
var olly = document.myform[“upload”].value;
if (olly == “”)
{
//do submit
alert(“form empty submit”);
document.myform.submit();
}
else if (olly !=””)
{
alert(“not empty clear then submit”);

//document.myform[“upload”].reset();
//document.getElementById(“myForm”).elements[“upload”].reset();
//document.myform.upload.value=null;
//document.myform[“upload”].value = “”;
//document.myform.getElementByName(“upload”).resetupload();
//document.getElementByName(“upload”).elements[“upload”].value = “”;
//document.myform.submit();
}

alert(olly);
}

</script>

</head>
<body>
<form name=”myform” enctype=”multipart/form-data” method=”post” action=”clear_test.php”>
<p>
<input type=”hidden” id=”max” name=”max” value=”52428800″ />
<input type=”hidden” name=”file” />
<input type=”file” name=”upload” id=”uploadid” size=”30″ title=”Browse for a File to Upload.”>

<SELECT NAME=”multiple_select” id=”multiple_select” onChange=”submitform();”>
<OPTION VALUE=”option1″>option1</OPTION>
<OPTION VALUE=”option2″>option2</OPTION>
<OPTION VALUE=”option3″>option3</OPTION>
<OPTION VALUE=”option4″>option4</OPTION>
<OPTION VALUE=”option5″>option5</OPTION>
<OPTION VALUE=”option6″>option6</OPTION>
</SELECT>
<input type=”submit” name=”submit1″ value=”Submit” >
</p>
</form>
</body>
</html>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienApr 09.2008 — You cannot set the value of a file upload field using JavaScript. You might try calling the reset(); function of a FORM tag DOM node:
var form = document.getElementById("my_form_id");
form.reset();
Copy linkTweet thisAlerts:
@agressoApr 24.2009 — Here is very good solution for this problem:

http://gusiev.com/?p=11
Copy linkTweet thisAlerts:
@toicontienApr 24.2009 — That solution works just fine as long as you don't need to refer to that file input field in JavaScript using the form.elements.[I]field_name[/I] syntax. When you add form fields to the DOM via innerHTML, the elements array of a FORM object does not get updated.
Copy linkTweet thisAlerts:
@agressoApr 24.2009 — Good to know.

By I prefer to get elements by id.

I don't think that fault described by you is a big problem.
×

Success!

Help @etnastyles spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...