Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stop manual editing of a form text box

    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
    Code:
    onFocus=this.blur()
    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

    thanks in advance for any help you can give this n00b
    blek..

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    Somewhere far beyond
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can display values in named div, for example:

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

    <script language="JScript">
    function change_it(id,text)
    {
    document.getElementById(id).innerHTML=text;
    }
    </script>

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

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    The idea is to stop people pasting text into a text box. Can this be done? Presumably not if JavaScipt is disabled.

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •