467,081 Members | 961 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

<input type file> Focus

hiya all
i would like to ask some help for a little javascript, here's my problem:
i have a html page with a <input type="file"> box, problem is i don't want the user to be able to write on the text field, he must use the browse button.
i tried a lot of codes but no one works for both IE and firefox
i tried to use onclick="blur",m but in that case the field and "browse button" didn't work

here's what i've done:

<form name="form1">
<input type="file" name="insertdoc" onclick="document.form1.otherinput.focus()">
<input type="hidden" name="otherinput">
</form>

works for firefox, you cannot write on the field, but browse button works well, problem is, this code don't work on IE error says: "can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus" well...IE, i hate you!

i tried to send my focus to another text field, in that case, browse button don't work....anyone with an idea how i can do this to work on IE?
thanks a lot for your help

Rei
Jan 11 '07 #1
  • viewed: 7676
Share:
6 Replies
acoder
Expert Mod 8TB
I can understand your problem and frustration. I'm not sure how you can solve the problem for IE, but no matter what they type into the input box, you can always check that the file exists on the server side. It just means a wasted trip to the server if the file doesn't exist and hence cannot be uploaded.
Jan 11 '07 #2
problem is, i really need it to be done that way :(
the user can't write on that textfield >_<
Jan 11 '07 #3
Took some thought but here is what I have:


<form name="form1">
<input type="file" name="insertdoc" onkeydown="return false">
<input type="hidden" name="otherinput">
</form>

Hope it helps :)
Jan 14 '07 #4
There is a very easy way past this by the way, which is pasting a value into it. It is all I could think of for IE.
Jan 14 '07 #5
Took some thought but here is what I have:


<form name="form1">
<input type="file" name="insertdoc" onkeydown="return false">
<input type="hidden" name="otherinput">
</form>

Hope it helps :)
that works, it's really cool.
thank you very much everyone for your great help!! (^_^)(_ _)(^_^)
Jan 15 '07 #6
acoder
Expert Mod 8TB
that works, it's really cool.
thank you very much everyone for your great help!! (^_^)(_ _)(^_^)
Good work johnhjohn for working that out. I didn't think about using onkeydown.
Remember reiyel that this isn't completely foolproof as john pointed out.
Jan 15 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by magix | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.