views:

216

answers:

3

Is there any way to hide the text box behind a DIV ?

I have a textbox which is supposed to be disabled so that user can not change the text. But i have onclick() event on the same textbox. If i am using "disabled-disabled" then onclick event is not working.

So, i am trying to make a DIV of same size with its z-index value higher then textbox so that onclick event can fire.

Please suggest me the better option. Thanks in advance.

Regards Lokesh Yadav

A: 

You can return false; in the onkeyup, onkeydown and onkeypress events of the textbox. This way, user will not be able to edit it. But your onclick will work.

<input type="text" onkeyup="return false;" 
onkeydown="return false;"
onkeypress="return false;"
onclick="alert('hi');">

I am not sure if you need to return false in all three keyboard events, but it just came to mind and I typed them. Maybe you could get away with two or even one of those events.

Senthil
works fine for me. Thanks Senthil!A small doubt:Is there any way to hide the "text cursor(|)" blinking when focus is on textbox?
Lokesh
Nice!..:) If any post answers your question, please mark it as the answer. I don't think I know how to hide the cursor. Will get back if I find out how to do it.
Senthil
ok. I will mark it as answer. i am eagerly waiting for your reply.. hope you will find some way to hide this cursor
Lokesh
Just did some searching in Google.. you could have done the same.. There seems to be no straightforward way to do this. It might turn out that there is no way to do this. You just have to keep searching. I can't seem to think of a solution to hide the blinking cursor.
Senthil
no worries. anyways thanks for your code, 90% of the problem is solved.for rest 10% .. will try my luck on Google :)
Lokesh
A: 

I suggest having the onclick event check if the textbox is disabled, and if it is, return false;

Kerry
But onclick will not fire if textbox is disabled
Senthil
onclick will not fire when disabled is true!! Is there any way to hide the "text cursor(|)" blinking when focus is on textbox?
Lokesh
@ Senthil. Good to know. I would delete my answer but Lokesh has asked another question.
Kerry
@ kerry: i am fighting with this cursur blinking thing. Client wants to get rid of this cursor. :)
Lokesh
Do you have a link?
Kerry
A: 

To prevent the user from changing the text in the textarea, why not use the readonly property?

anon commenter