JavaScript to prevent user from removing *part* of a value
Posted: Wed Feb 08, 2006 11:41 am
To give an idea of why I need this I'll explain.
I'm writing a tool that mimics a command line console... it uses JavaScript on the client side along with a bit of AJAX.
The cursor sits inside an input (type="text") element waiting for commands to be typed. This box has a prompt inside it:
Now when the command is sent, JavaScript simply removes the prompt text. The user can actually just backspace to delete the prompt at the moment though... I don't want that
I actually want to somehow stop the caret from going in that part of the text box (hmm... I think I'm starting to figure this out in my head with document.selection).
I'm very aware that there are better ways to place the prompt there (use a div or span) but this just means that the styling and spacing will be consitent with the rest of the app... I'll change it if there really isn't a way to do this.
Anyone got any bright ideas?
I'm writing a tool that mimics a command line console... it uses JavaScript on the client side along with a bit of AJAX.
The cursor sits inside an input (type="text") element waiting for commands to be typed. This box has a prompt inside it:
Code: Select all
<input type="text" name="foo" value="prompt> " onkeyup="checkCommand()" />I'm very aware that there are better ways to place the prompt there (use a div or span) but this just means that the styling and spacing will be consitent with the rest of the app... I'll change it if there really isn't a way to do this.
Anyone got any bright ideas?