Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable a text box...

Status
Not open for further replies.

dodgyone

Technical User
Joined
Jan 26, 2001
Messages
431
Location
GB
I have a form type="file" on my page so users can search for an image file to be uploaded to the server.

I really need to be able to stop the user entering their own text into the text box provided and enable them to just use the button to browse for the item that they want.

Can this be easily achieved?

Many thanks...
 
You can do this a couple of different ways:

<input type=textbox disabled=true>

or you can place code for the textbox's onkeypress and onkeydown events.

onkeypress='return false'

onkeydown='return false'

But if you don't want the user to use the textbox at all why even display one. I would use a Div or span tag and just update it's innerHTML/innerTEXT to the path the user browses to.
&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Or you can blur the box...

<input onFocus=&quot;this.blur()&quot;> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
It's sad that some Americans proudly turn their backs on the very Flag the gives them the opportunity to do just that... - Mike
 
It's a type=&quot;file&quot; field though so blur doesn't enable you to use the browse button or the text field.

The file field has a text box and button as standard. Just wondered if you could disable the text field part.

 
Code:
<input type=&quot;file&quot; name=&quot;file&quot; onKeyPress=&quot;return false;&quot;>

Should give you what you need --James
 
This still allows a user to browse a file and then delete a few characters from the filename.

I don't have a solution but just thought I'd throw that in ;-)
BDC.
 
Many thanks... onKeyPress=&quot;return false works like a charm ;o)
 
BDC2, you're right! It seems the backspace isn't recognised as a keypress? Do you know why this is? --James
 
I have no idea, I'm just good at breaking things ;-)
BDC.
 
Another option is to change the style of the input style=&quot;border;0px&quot; so that the user doesn't see the text box - which is no where near as good as the onKeyPress solution... Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
It's sad that some Americans proudly turn their backs on the very Flag the gives them the opportunity to do just that... - Mike
 
Just been playing with this a bit - it seems you can get it to recognise virtually any other key on the keyboard by using event.keyCode except the backspace!

Can't see a way round this minor detail unfortunately... --James
 
You can also select with a mouse and DELETE - hmmm... Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
It's sad that some Americans proudly turn their backs on the very Flag the gives them the opportunity to do just that... - Mike
 
Indeed. I guess I'd have to question why dodgyone required this functionality in the first place? --James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top