Replace default text onMouseDown, with new text, so user can type after the new text
Hi Forum Whizzes,
This is such a trivial little thing, but it is really bothering me that I can't make it work.
I have a form which contains many input fields for Name, Address, Website, Email, Phone Number, etc. One of the pieces of data I would like the user to supply is the name of their Instagram account ie: @AcrobatJavascriptDunce (Which should probably be mine...)
Rather than have external titles for the fields, the style on the form is that the text box contains default text, which tells the user what they need to put in the box. So the default text for the Website field is "Website", obviously, and the default text is displayed in red. I have it set up so that when the user clicks on that field, the default text disappears, and the cursor is in the box ready to type, and when they DO type, the text is now displayed in black. It all works very nicely for my other fields, but for the Instagram field, I would like the action to be subtly different.
When the user clicks on the default text (which happens to be "@instagram" as that tells them the format I would like them to enter the name in), I want the red text to disappear as before, but instead of a blank field, I want the field to just contain the "@", so that when they type, whatever they type comes after the "@". This is simply a little timesaver for using the form, but it will be a nice convenient touch.
At the moment I am using the following script, set as an action onMouseDown:
if (event.target.value == event.target.defaultValue) {
event.target.value="@";
event.target.textColor=color.black;
}
It works apart from one tiny-but-crucial detail: when I click in the field, the default text disappears, and a black "@" takes its place, but unfortunately, the cursor is to the left of the "@" sign, so anything that the user types into the box ends up on the wrong side, and the Instagram name has the "@" at the end!
Is there a way to specify that the cursor appears at the end of the text, rather than before it?
Thanks so much for your help. Any advice will be VERY gratefully received.
Best wishes,
NathanG
