Click to See Complete Forum and Search --> : input type file


sergiodegioia
11-24-2003, 08:52 AM
How can the HTML input field of file type be deleted by Javascript code. Note I say deleted not generically modified

sergiodegioia
11-24-2003, 09:37 AM
I'll try to be clearer:

...
<FORM NAME="formName">
<SCRIPT>
function delete{
document.formName.file.value = "";
}
</SCRIPT>

<input name="file" type="file">
</FORM>
...

When delete is called it does not delete anything.
How can I get it work?

Pittimann
11-24-2003, 10:04 AM
Hi!

As far as scripting is concerned, the value of the file input is readonly! The only way to change the text in the field is, that the user does it (put something in our "out").

Cheers - Pit

P.S. There is a trick to manipulate this but it still requires action taken by the user - so it is of no use for you...

gil davis
11-24-2003, 10:09 AM
By using the DOM method "removeChild()":
document.formName.removeChild(document.formName.fieldName);
If you just want to clear the box, you can reset the whole form:
document.formName.reset();

sergiodegioia
11-24-2003, 10:46 AM
I get an Invalid argument Error using the first approach, that I am interested in.

gil davis
11-24-2003, 11:47 AM
<head>
<script>
function dele() {
document.formName.removeChild(document.formName.fi);
}
</script>
</head>
<body>
<form name="formName" onsubmit="return false">
<input type="file" name="fi"><br>
<input type="button" value="Delete" onclick="dele()">
</form>
</body>

sergiodegioia
11-24-2003, 12:22 PM
OK, I was very unclear
I want just delete the value of a file type input field, not the input field as a child, not all the values of a form.

Maybe I can save all the form values in an array, then invoke reset() on the form, and finally restore all the object form except the file type input field.
May anyone suggest me the right algorithm, if what I say have some sense?

Pittimann
11-24-2003, 12:56 PM
Hi!

In this forum you will find many threads dealing with how to pass form values to another window or whatever. Read these threads, act accordingly and don't worry about the file input.

Its' value will be ""! (like I said before: it is readonly)

Cheers - Pit