View Full Version : stop manual editing of a form text box

04-02-2003, 12:33 PM
I'm looking for a way to make it so the values in a forms text box cannot be changed by the user, but can still be changed through a script.

I know about


but i'm fairly certain this does not work on all browsers. It also does'nt stop people from being able to copy, highlight the box, then paste in anything they want.

It's for a javascript game, and since I don't know how to go about displaying certain values to the player through means other than through form boxes I need to squash this way to cheat ;)

P.S. - If you know of a way, please direct me to a way of displaying things without having to use text boxes. That would solve my problem as well :thumbsup:

thanks in advance for any help you can give this n00b :D

04-02-2003, 12:53 PM
You can display values in named div, for example:

<div id='some_id'></div>

<script language="JScript">
function change_it(id,text)

<a href="#" onclick="change_it('some_id','Text to display');return false">Change contents of named div</a>

Philip M
04-02-2003, 07:14 PM
The idea is to stop people pasting text into a text box. Can this be done? Presumably not if JavaScipt is disabled.

04-03-2003, 12:52 AM
You can alter displayed text anywhere - it doesn't need to be a DIV, necessarily. afaik, <input onfocus="this.blur()"> works everywhere, as long as JS isn't disabled. If you're willing to lose support of a few older browsers, do it in HTML:

<input type="text" readonly="readonly">

..or, for better support:

<input type="text" readonly="readonly" onfocus="if(!this.readOnly)this.blur()">