PDA

Click to See Complete Forum and Search --> : Textboxes...


turfbult
Apr 23rd, 2001, 03:05 PM
Hello,

I have a textbox - "<input type="text" name="name" size="20">"

Is there a way in which I can "lock" this textbox - ie. disallow users
from editing whatever is inside this textbox.

I actually want to disallow the user from entering into this AT ALL - he
must not even be able to place the cursor within here.

Another question... How can I set the focus to this textbox, so that the cursor is automatically
placed within it when the page is loaded.

Can it be done??

Thanks,
T

monte96
Apr 23rd, 2001, 08:34 PM
Yes on both counts....

To disable:

//Javascript:
MyForm.MyTextBox.disabled=true;

To set focus:

//Javascript:
MyForm.MyTextBox.focus();

monte96
Apr 23rd, 2001, 08:34 PM
Oh.. stick that focus method in the window_onload() event...

JoshT
Apr 24th, 2001, 06:35 AM
<input type="text" readonly> is part of HTML 4.0.

monte96
Apr 24th, 2001, 10:46 AM
Yes, but you can't always count on a 4.0 browser... (I hate having to code for the lowest common denominator but...)

Also, you can not set focus to a readonly textbox or a disabled textbox. In fact, if it is disabled and you try to set focus, it will generate an error.

So, if you are using the disabled method, enable it before setting focus.

bubba
Apr 24th, 2001, 11:22 AM
then screw 'em.

If you want the text box to appear disabled/readonly:

<input TYPE="TEXT" VALUE="Yeah, baby!" disabled>

the readonly property makes the box look normal, disabled shades it.

Jeh
Apr 24th, 2001, 11:43 AM
as usual im not sure if im gonna be right here or not.

with the readonly it makes it uneditable but still looks normal as previously mentioned, the disabled command also hides the info in the field when submitted so if u submit a form with the disabled field in you wont be able to retrieve the info from within, but you can with readonly, I think...

bubba
Apr 24th, 2001, 12:45 PM
Disabled text box values can't be passed, but readonly can

turfbult
May 9th, 2001, 01:15 AM
Hello guys,

I only got a chance to read the replies now!! Thank you very much - this is exactly what I was looking for!!

Monte96 (or anyone),

Can you please give me some example code of the window_onload() event!?

I'm not very clued up with Java. Do you just put this event right at the top of your page and it will "fire" whenever the page is loaded??

Thanks,
T

monte96
May 9th, 2001, 12:07 PM
Ok.. first off, you won't use Java, you'll use Javascript. They are similar only in name.

The window_onload() event will fire if you put it in the BODY tag's event handler attribute like:

<BODY onload="window_onload()">

You will put a script tag in the HEAD section of the page, be sure to specify the language and remember that javascript is case sensitive:

<HTML>
<HEAD>
<SCRIPT language=javascript>
function window_onload()
{
//Put your code for the onload event here
}
</SCRIPT>
</HEAD>
<BODY onload="window_onload()">
...

turfbult
May 9th, 2001, 02:27 PM
Thanks Monte96, and thanks for the answer on the formatting of currency values in my other thread.

T