Using JQuery to force cursor to start on the third character position of a text field

I am trying to find a way so that when a user clicks on a form text field I would like the cursor to only start after the third character within the text field.

The reason for this is that I need the first 3 characters to be uneditable so the user can only start typing after the third character. It must not be possible to click on the first 3 characters.
mike99cAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F PCommented:
So, why don't you set it to static text in a label outside of the field, and then parse whatever they input in with the form submission in javascript to add those first 3 in at that point, or on the side handling the db to make sure that the first 3 have that value, if not add it?
0
F PCommented:
<label for="textValue">ABC</label> <input type="text" name="textValue" id="textValue" value="DEFG"> 

Open in new window

0
mike99cAuthor Commented:
OK I can see in the example given that you initialise the text field with "DEFG". But if the user edits the text field they can still delete the text.

For my requirement I want to add the first 3 characters say ABC in the text field. I then want the user to only edit the text field AFTER the ABC and not be able to delete the ABC.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

F PCommented:
Right, so in my example, you'll notice that the ABC is not editable since it's a label. Just for the value to appear in front of the input, I put it there, but in reality if the user doesn't need to edit the characters, they don't need to appear in the textbox. I would split the string, and only only that part of the value that they can edit. I hope that clarifies a bit.
0
mike99cAuthor Commented:
Thanks Frank but what I am really looking for is a JQuery solution in which the first 3 characters appear within the text field itself and the cursor is forced to start after the 3rd character. I did originally think of a similar solution to yours but this post is about keeping the 3 characters within the text field.
0
F PCommented:
Well, I found this which seems to do exactly what you're asking for in the jQuery only...

https://gist.github.com/DrPheltRight/1007907

... But, don't forget you still need to validate the input on the backend before you submit it to the database. Javascript can always be disabled prior to hitting submit or POSTing the values.
0
F PCommented:
Capture keydowns and mouseclick events to validate the position with that and move accordingly.
0
F PCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.