Click to See Complete Forum and Search --> : clearing file input field - send keystroke?


welton
07-17-2003, 03:56 PM
hello,

i want to clear and disable an input field of type file if a user unchecks a checkbox. i got the disabled part.

i know document.orderForm.user_graphic.value=''; won't work...

when i looked this up in the archives, i saw a suggestion to create a separate form for the input field, then use a Reset button -- but i'd rather not create a second form.

is there a way, for example, to do something like this:


function fileChooserDisabled(dis)
{

if(dis)//abled
{

document.forms.orderForm.user_graphic.focus(); // set focus in the field

*** send keystroke to delete field's contents ***

}

document.orderForm.user_graphic.disabled=dis;

}


kludgy idea, i know, but i DON'T want a graphic submitted if the checkbox is unchecked, and i don't want to create a second form. other possibilities?

any suggestions appreciated, thanks in advance.

fla5hba5h
07-17-2003, 04:42 PM
Originally posted by welton
i know document.forms.orderForm.user_graphic.value=''; won't work...


Why not?

welton
07-17-2003, 05:17 PM
Originally posted by fla5hba5h
Why not?

because when i run this:


function fileChooserDisabled(dis)
{

if(dis)//abled
{

document.orderForm.user_graphic.value=''
var title = eval('document.orderForm.user_graphic.value');
alert(title);
}

document.orderForm.user_graphic.disabled=dis;

}


i still get a path to the file in the alert, and the file name is still in the input field. i'm assuming the file will send on submit, won't it?

no luck on Mac IE 5.1.6 or Mozilla 1.2.1

Charles
07-17-2003, 05:24 PM
What's with the "eval()"?

welton
07-17-2003, 06:02 PM
Originally posted by Charles
What's with the "eval()"?

it was in a script i've copied/pasted/modified for alerts.

is it wrong? deprecated? it hasn't generated any errors, and i see it in other scripts from time to time.

also, is there any way to send a keystroke to delete the file field's contents?

Charles
07-17-2003, 06:36 PM
eval('document.orderForm.user_graphic.value')[font=georgia]evaluates and then does the same thing asdocument.orderForm.user_graphic.valueonly it takes more work.

fla5hba5h
07-17-2003, 06:37 PM
Originally posted by welton
because when i run this:


function fileChooserDisabled(dis)
{

if(dis)//abled
{

document.orderForm.user_graphic.value=''
var title = eval('document.orderForm.user_graphic.value');
alert(title);
}

document.orderForm.user_graphic.disabled=dis;

}


i still get a path to the file in the alert, and the file name is still in the input field. i'm assuming the file will send on submit, won't it?

no luck on Mac IE 5.1.6 or Mozilla 1.2.1

I think you have to do document.orderForm.user_graphic.value=""

not document.orderForm.user_graphic.value="

welton
07-17-2003, 06:37 PM
OK, thanks.

as for the keystroke question?

on edit: the above was to charles... i'll check the suggestion.

welton
07-17-2003, 06:43 PM
Originally posted by fla5hba5h
I think you have to do document.orderForm.user_graphic.value=""

not document.orderForm.user_graphic.value="

thank you, but alas, no luck, the file still shows up in the grayed out field.

i'm thinking the kludge might work...?

Exuro
07-17-2003, 10:51 PM
Originally posted by fla5hba5h
I think you have to do document.orderForm.user_graphic.value=""

not document.orderForm.user_graphic.value="

I think he thought that '' was a single quote instead of two apostrophies... Anyway, I don't think you can clear a file element without resetting the whole field. If I were you, I'd just not clear it. I mean, it's not like they can do anything to it if it's disabled. You have the checkbox's value, so whatever you were doing with the data you can just say something like if (checkbox == checked) and then you're good!

welton
07-17-2003, 11:22 PM
OK then.

thanks,

fla5hba5h
07-21-2003, 03:19 AM
Originally posted by Exuro
I think he thought that '' was a single quote instead of two apostrophies...

Yes, I did.